cli command to place one image over another

Posted this elsewhere by mistake, kind of…

Can I use gmic cli to input two images with the first being the ‘background’ and the second being ‘foreground’, basically one layered over the other and then flattened? And the foreground is smaller than the background so it should be centrered over it. What would the cli command look like? Both images are RGBA png’s. Thank you.

Think you want the image command (shortcut: j)

gmic run '512,512,1,3,lerp([20,70,120],[130,210,240],y/(h-1)) -name. background 32,48,1,3,[255,200,0] -name. sprite image[background] [sprite],100,80'

This pipeline creates two images, a large one (512×512) with a graduated background and a smaller, solid yellow image. The command “pastes” the small yellow image on top of the background with the upper left corner of the small yellow image (aka ‘sprite’) at [100,80].


For working with alpha channels, use the very similar imagealpha. Shortcut ja

1 Like

I think the simplest way to do this is:

$ gmic background.png foreground.png blend alpha output out.png

Ok thank you for replying.
I’m wondering what the command would look like if the background was sized 1280x720 and named ‘image1.png’, and the ‘sprite’ was 361x421and called ‘image2.png’, with it outputting a new image called ‘new.png’… so, how can I get the image 2 centered over image 1 and rendered as an outputted png. I cannot fathom quite what to do, you’ll have to excuse the lack of knowledge on the intricacies of gmic on my part, but I do appreciate the pointers!
Edit: Cross posted with David. I will try that, thank you.

Yes I should have known this really as I had similar query that was solved by utilising ‘blend’, thank you kindly. :grinning: