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

Calling resize returns a ImageBuffer <Rgba<_>, _> for DynamicImage #2331

Closed
emsknock opened this issue Sep 22, 2024 · 1 comment
Closed

Calling resize returns a ImageBuffer <Rgba<_>, _> for DynamicImage #2331

emsknock opened this issue Sep 22, 2024 · 1 comment

Comments

@emsknock
Copy link

See the following:

use image::ImageReader;
use image::imageops::{resize, FilterType};

let input_img = ImageReader::open(input_path)?.with_guessed_format()?.decode()?;

let scaled = resize(
	&input_img,
	target_width,
	target_height,
	FilterType::Lanczos3,
);

The type of scaled is now ImageBuffer<Rgba<u8>, Vec<u8>>. This is despite the fact that the image at input_path can be a jpeg image; it shouldn't be possible (at least to my understanding) for it to have an alpha channel. This causes problems when I move on to save the image:

let output_path = "output.jpeg";

scaled.save(output_path)? // → UnsupportedError { format: Exact(Jpeg), kind: Color(Rgba8) }

I can work around this with something like:

DynamicImage::from(scaled).to_rgb8().save()

But that's not very nice to use when the input/output can also be e.g. transparent png files.

This seems like it could be related to #2274, #2237, and #2227.

@HeroicKatora
Copy link
Member

Yes. Not a bug.

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