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 » 2019-01-05T09:46:08-07:00

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: 24465
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 » 2019-01-05T11:10:24-07:00

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 » 2019-01-05T11:39:32-07:00

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: 24465
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 » 2019-01-05T12:26:25-07:00

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: 664
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 » 2019-01-05T12:53:56-07:00

jay1 wrote:
2019-01-05T11:39:32-07:00
Need 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