Crop one image, montage with another

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
jay1
Posts: 2
Joined: 2019-01-05T09:17:48-07:00
Authentication code: 1152

Crop one image, montage with another

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop one image, montage with another

Post 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
jay1
Posts: 2
Joined: 2019-01-05T09:17:48-07:00
Authentication code: 1152

Re: Crop one image, montage with another

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Crop one image, montage with another

Post by fmw42 »

Code: Select all

convert \
1.jpg \
\( 2.jpg -gravity center -crop 300x80+0+0 +repage \) \
-gravity center \
-compose over -composite \
result.jpg
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Crop one image, montage with another

Post 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.
Post Reply