Copy an area of an image to itself

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
jem
Posts: 2
Joined: 2014-09-07T09:42:02-07:00
Authentication code: 6789

Copy an area of an image to itself

Post by jem »

Hello,

Using batch processing, how can I copy a rectangle area of an image to another area of that same image please?

Thanks,
J.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy an area of an image to itself

Post by fmw42 »

I do not think that mogrify will allow you to do that, since the overlay image must be the same for all input images. So I think you will need to write a script to loop over each image and use convert to do the processing. The script will be OS dependent. What version of IM are you using and what platform.

The basic convert command will be something like the following:

Unix:

Code: Select all

convert image \( -clone -crop WxH+X1+Y1 +repage \) -geometry +X2+Y2 -compose over -composite result
Window:

Code: Select all

convert image ( -clone -crop WxH+X1+Y1 +repage ) -geometry +X2+Y2 -compose over -composite result
Where WxH+X1+X2 is the subsection to be copied W=width, H=height, X1,Y1=top left corner of subsection and X2,Y2 is the new location in the input for placement of the top left corner of the subsection

See
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
jem
Posts: 2
Joined: 2014-09-07T09:42:02-07:00
Authentication code: 6789

Re: Copy an area of an image to itself

Post by jem »

Hello fmw42,

Thank you very much for your fast answer. It perfectly solved my need!

J.
Post Reply