Copy and paste regions

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?".
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Copy and paste regions

Post by anthony »

resize has no location, it just resizes the image to the pixel sizes specified, or to the percentage specified.

So you need to do things step by step
  • read the image
  • crop (and +repage) the part of the image wanted
  • resize to the new size in pixels
  • set a geometry position
  • read destination image
  • swap two image so the croped image is second (overlay) image
  • set a geometry position
  • compose the two together
  • save the result
You can reorder operations by using parenthesis to do things 'on the side' but essentually the above is all the steps needed.
The steps can be modified for non-rectangular areas (masking instead of cropping, or for warping and distorting the image into a new shape or location before overlaying, but essentually the same basic steps should be followed.

You can break up the steps into separate commands, or insert other modifications, but the basic steps remain.

NOTE : we are not here to do the work for you, bt help and guide you to the best solution. With actual examples we can generate actual commands, but it is better if you actually understand what individual steps should be taken.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy and paste regions

Post by fmw42 »

galv wrote:Fred, if I'm not mistaken that resizes the image to half. Which is not what I want.. :/
Anthony, how? How do I specify the final size as pixels? Also, what is loaction?

I though all you wanted was an example of using fx calculations. Sorry. See Anthony's outline above. You don't need percents. You just need to know how big to resize (in pixels or percent). If pixels is easier that is fine. -resize WidthxHeight

Then you just need to know where to place the upper left corner of the resized image into the background image.



convert backgroundimage \
\( image2 -crop W1xH1+X1+Y1 +repage -resize WW1xHH1 \) -geometry +x1+y1 -compose composemethod -composite \
\( image2 -crop W2xH2+X2+Y2 +repage -resize WW2xHH2 \) -geometry +x2+y2 -compose composemethod -composite \
...
resultimage

Where WW1xHH1 is the new size you want to make the subsection from the crop and x1 and y1 are the coordinates in the background image where you want the resized subsection's upper left corner to be placed

If you could post a link to an example image or images and explain what you want, then we could give you a better example.
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Copy and paste regions

Post by galv »

Thank you both!!
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Copy and paste regions

Post by galv »

Is there a way to copy instead of crop? Meaning I want to preserve the original image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy and paste regions

Post by fmw42 »

galv wrote:Is there a way to copy instead of crop? Meaning I want to preserve the original image.

Please clarify - what do you mean by copy in this context vs crop?

If you want the whole image and not a subsection, then just leave off the -crop ... +repage

If the second image is the same as the first, then replace image2 with -clone 0

see http://www.imagemagick.org/Usage/basics/#clone
galv
Posts: 62
Joined: 2010-05-23T17:35:59-07:00
Authentication code: 8675308

Re: Copy and paste regions

Post by galv »

I mean that 'crop' is like 'cut' (think as in desktop file manager). It ruins the original image (it cuts pieces off). I would prefer 'copy' instead of 'cut', which would leave the original image intact.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy and paste regions

Post by fmw42 »

galv wrote:I mean that 'crop' is like 'cut' (think as in desktop file manager). It ruins the original image (it cuts pieces off). I would prefer 'copy' instead of 'cut', which would leave the original image intact.

Sorry I still do not understand. If you want the whole image and not just a piece of it, then just leave off the -crop ... +repage.


Perhaps it would be helpful to list out the functional steps you want to do to process your image(s) and identify if you have just one input or more than one input. I am still not clear exactly what you are trying to do. I don't know if this a a new set of processing or your original one and still don't quite understand your original one.

Do you have any example from somewhere on the Internet that can explain what you are trying to accomplish?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Copy and paste regions

Post by anthony »

galv wrote:Is there a way to copy instead of crop? Meaning I want to preserve the original image.
That is the function of the 'clone' and the parenthesis. It makes a 'copy' of the image on-the-side whcih can then be cropped and repaged (remove virtual info about the crop). At the end of the parenthesis, you will then have two images in memory, the original and the cropped version.

I really suggest you read IM Examples, Image Sequences.
http://www.imagemagick.org/Usage/basics/#image_seq
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply