Replace part of an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Flashlight
Posts: 3
Joined: 2010-08-18T08:36:48-07:00
Authentication code: 8675308

Replace part of an image

Post 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!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace part of an image

Post 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
snibgo's IM pages: im.snibgo.com
Flashlight
Posts: 3
Joined: 2010-08-18T08:36:48-07:00
Authentication code: 8675308

Re: Replace part of an image

Post by Flashlight »

Thank you for your answer. It works now!
Hemanth Reddy
Posts: 1
Joined: 2017-04-15T21:56:52-07:00
Authentication code: 1151

Re: Replace part of an image

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace part of an image

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply