Little Problem with ImageBuffer/DynamicImage in crate image

Hello,

i have tryed to resize an image before overlay.

let mut img_bg = image::open(&Path::new("gog_bg.png")).ok().expect("Opening image failed");
			let mut img_png = image::open(&Path::new(&icoPath2.to_string())).ok().expect("Opening image failed");

			let mut img_png2 = imageops::resize(&mut img_bg,100,100,FilterType::Lanczos3);
			let mut img_png3 = image::load_from_memory (&img_png2).unwrap();

			imageops::overlay(&mut img_bg, &img_png, 0, 0);

Compile its okay but an Backtrace output:

thread 'main' panicked at 'called Result::unwrap()on anErr value: UnsupportedError("Unsupported image format")', src\libcore\result.rs:997:5

Seems like load_from_memory was the false idea:).

My Problem is that imageops convert it into an ImageBuffer and i can this not convert into an DynamicImage.

imageops::overlay(&mut img_bg, &img_png2, 0, 0);
    |                                            ^^^^^^^^^ expected enum `image::DynamicImage`, found struct `image::ImageBuffer`

This happened when im use img_png2 directly after the resize.

Thx

1 Like

I've just used the image crate for some simple image processing. I found it a little confusing to use.

@derekdreery HI, yes indeed the modul/crate images is a little confusing to use. But I'm happy to have an modul/crate that handle the most popular image formats and gives me some little functions/methods to manipulate this images. I think in should use the issues on Github:).

Do you know another modul/crate for my needs?

Hello,
i have found the solution. Why imageops only have overay functions i have logical used imageops for resizing, now i use DynamicImage directly for resizing and imageops only for overlay.

let mut img_png2 = img_png.resize(220,220,FilterType::Lanczos3);
			imageops::overlay(&mut img_bg, &img_png2, 18, 18);

I basically had the same experience as you - it did what I wanted, but it was hard to get working!

@derekdreery I recommend the Github-Issues for this special crate, he has an special Question Issue and has annouced a new version of image that resolve some issues.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.