Page 1 of 1

Crop one image, montage with another

Posted: 2019-01-05T09:46:08-07:00
by jay1
Hi. I have a question. I have two images, and I need to merged them in one

Let's say 1.jpg and 2.jpg. They are the same dimension/size

So I need to cut the middle of 1.jpg 300x80 size part exactly on the middle of the pic. Take that middle part of 300x80 part from 2.jpg. Merge result in one file/save

Sizes differ. But 1.jpg and 2.jpg always are exactly the same size. AND the part that has to be cropped/replaces is always 300x80 and exactly at the "middle"

can anyone help with exact string/code? Thanks

Re: Crop one image, montage with another

Posted: 2019-01-05T11:10:24-07:00
by fmw42
Merged how? One above the other appended? Side by side appended? Lets assume the first. You also do not say what version of Imagemagick nor what platform. Lets assume unix-like system and IM 6.

Code: Select all

convert \
\( 1.jpg -gravity center -crop 300x80+0+0 +repage \) \
\( 2.jpg -gravity center -crop 300x80+0+0 +repage \) \
-append \
result.jpg
____________________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: Crop one image, montage with another

Posted: 2019-01-05T11:39:32-07:00
by jay1
Unix system

Didn't explain it correctly.
Need to remove 300x80 pxl part in the middle of 1.jpg and replace it with the middle part of 2.jpg

So, the middle of the 2.jpg becomes the middle of 1.jpg

NOT append cropped centers

Re: Crop one image, montage with another

Posted: 2019-01-05T12:26:25-07:00
by fmw42

Code: Select all

convert \
1.jpg \
\( 2.jpg -gravity center -crop 300x80+0+0 +repage \) \
-gravity center \
-compose over -composite \
result.jpg

Re: Crop one image, montage with another

Posted: 2019-01-05T12:53:56-07:00
by GeeMack
jay1 wrote: 2019-01-05T11:39:32-07:00Need to remove 300x80 pxl part in the middle of 1.jpg and replace it with the middle part of 2.jpg
The solution offered above by fmw42 is about as simple as it gets. Here's an example of the same concept arranged in a slightly different order...

Code: Select all

convert 2.jpg -gravity center -crop 300x80+0+0 1.jpg +insert -composite result.png
That reads in "2.jpg" and crops it to keep just the center 300x80 section. Then it reads in "1.jpg", inserts it at the beginning of the list, and composites the cropped piece of "2.jpg" over the center of "1.jpg". This should work with any size of input images.