Page 1 of 1

Replace part of an image

Posted: 2014-05-23T08:03:23-07:00
by Flashlight
I have two images of same size. I want to replace an area given by location X,Y with size W,H of image 1 with exact same located area of image 2 (or vice versa).

I tried this without success (think that X,Y,W,H are replaced with their desired values):

Code: Select all

convert.exe IMAGE1.png ( IMAGE2.png -crop WxH+X+Y +repage ) -compose Copy -geometry +X+Y OUTPUT.png
I only get two images OUTPUT-0.png and OUTPUT-1.png but no overlay of both. What would be the correct one-line command?

Thanks a lot!

Re: Replace part of an image

Posted: 2014-05-23T08:43:17-07:00
by snibgo
"-compose over" is just a setting, and does nothing without "-composite". Without "-composite", the two images are not combined, so there are two outputs.

You could write it like this:

Code: Select all

convert.exe x1.png ( x2.png -crop 300x300+100+150 +repage ) -gravity NorthWest -geometry +100+150 -compose Copy -composite OUTPUT.png

Re: Replace part of an image

Posted: 2014-05-23T13:01:23-07:00
by Flashlight
Thank you for your answer. It works now!

Re: Replace part of an image

Posted: 2017-04-15T22:02:36-07:00
by Hemanth Reddy
I was exactly searching for this
please send me your code for replace a part of the image with another image
I have my project submission
Please send me
Thank You

Re: Replace part of an image

Posted: 2017-04-16T06:08:28-07:00
by snibgo
@Hemanth Reddy: The question has been answered. If you have another question, please ask it. Otherwise, I will assume you are a spammer.