Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid buffer length issue #29

Closed
ChanManChan opened this issue Jun 1, 2024 · 1 comment
Closed

Invalid buffer length issue #29

ChanManChan opened this issue Jun 1, 2024 · 1 comment

Comments

@ChanManChan
Copy link

ChanManChan commented Jun 1, 2024

[1] assertion left == right failed: Invalid buffer length: expected 181600 got 136200 for 200x227 image
[1] left: 181600
[1] right: 136200

let src_image = ImageReader::new(std::io::Cursor::new(file_data))
            .with_guessed_format()
            .unwrap()
            .decode()
            .unwrap();

        let src_aspect_ratio = src_image.width() as f32 / src_image.height() as f32;

        let dst_width = 200_f32;
        let dst_height = dst_width / src_aspect_ratio;

        let dst_width = dst_width as u32;
        let dst_height = dst_height.round() as u32;

        let mut dst_image = Image::new(dst_width, dst_height, src_image.pixel_type().unwrap());
        resizer.resize(&src_image, &mut dst_image, None).unwrap();

        let mut result_buf = BufWriter::new(Vec::new());
        let written_image_error = PngEncoder::new(&mut result_buf)
            .write_image(
                dst_image.buffer(),
                dst_width,
                dst_height,
                ExtendedColorType::Rgba8,
            )
            .err();

This happens when I try to iterate over incoming images to resize them one by one. But when done one at a time the resize works fine.

Please help me with this. Thank you :)

Note: I'm using AXUM 7.5 with axum_typed_multipart to get the images

@Cykooz
Copy link
Owner

Cykooz commented Jun 2, 2024

In which line of code does the error occur? Is it the line with .write_image(...).err()?
Are you sure that all of your images have ExtendedColorType::Rgba8 color type?

@Cykooz Cykooz closed this as completed Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants