How can i copy and/or resize 2 Images to an new images

Hello,

i have two pngs (bg.png) and (fg.png) and i would load bg.png as background and copy as forverground fg.png over this bg.png?

Cool it was when i can play with fg.png and set coordinates and width and heigth.

It would be nice if the transparency channel will be conserved.

thx

It looks like you can do it with the image library https://docs.rs/image/0.21.1/image/imageops/fn.overlay.html

@notriddle Thx, but i have problems with the api-doc from crate image:

let img = image::open(&Path::new(&newPngPath.to_string())).ok().expect("Opening image failed");
let img2 = image::open(&Path::new(&newPngPath2.to_string())).ok().expect("Opening image failed");

I can using img/img2.blur() and some other functions and img/img2.save functioned well, too.

But overlay don’t functioned.

Do you have an error message from when you try?

@notriddle I think i don’t understand the whole process how i can a loaded image-ref-var like img3 manipulate. Do you have some code-snippet for me how i can use imageops?

Once you’ve loaded the images, you’ll need to run something like this:

let mut img = image::open(&Path::new(&newPngPath.to_string())).ok().expect("Opening image failed");
let img2 = image::open(&Path::new(&newPngPath2.to_string())).ok().expect("Opening image failed");
image::imageops::overlay(&mut img, &img2, 0, 0);

@notriddle Functioned perfectly.

For my understandings. The function overay in the module imageops don’t have a return value, rather the function takes the two image-objects/reference and change the img-variable within his function?

My fault was i have handle imageops like image::save.

In the https://docs.rs/image/0.21.1/image/imageops/fn.overlay.html i don’t can read that i need the img-variables (I stand for image-object?) but i can now see it has no return value and wtf yes top and bottom are the layers. Hmm very hard to understandable.

image::imageops::overlay is also an static class, thats what i understand, but i hope in the next time i will more undertand strage new rust mechanism.

What are the difference between .function and ::function the path in the modules? Sorry my head burns a bit:).