Moving the crop position inside windows in collage

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
feanoro
Posts: 3
Joined: 2017-08-16T02:12:59-07:00
Authentication code: 1151

Moving the crop position inside windows in collage

Post by feanoro »

I have working script which makes a "collage" using convert script:

Code: Select all

convert 
( "1.jpg" -resize x2322 -gravity center -crop 1500x2322+0+0 +repage -gravity east -background white -splice 10x0 )
( "2.jpg" -resize x2322 -gravity center -crop 1500x2322+0+0 +repage ) 
+append -bordercolor white -border 20 result.jpg
The result then looks like this: https://www.awesomescreenshot.com/image ... 9a1cc88efe

I want to achieve:
- Move individual images inside their collage tiles by X and Y (aka dragging the crop frame around the image in Photoshop).
- Do not change size of the resulting collage (3000x2322 +borders ).

Version: ImageMagick-6.9.2
Any advices? Thank you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Moving the crop position inside windows in collage

Post by snibgo »

You have "-crop 1500x2322+0+0". Does changing the X and Y components do what you want? Eg "-crop 1500x2322+123+456".
snibgo's IM pages: im.snibgo.com
feanoro
Posts: 3
Joined: 2017-08-16T02:12:59-07:00
Authentication code: 1151

Re: Moving the crop position inside windows in collage

Post by feanoro »

No, it changes the size of the image.

Just take 2 large images and try it yourself with +200+234 and with +0+0. You will see that resulting size changes instead of just cropping the image at given coords
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Moving the crop position inside windows in collage

Post by snibgo »

The X and Y offsets specify where the crop should begin. "-crop" doesn't resize. For example, using toes.png:
Image

Code: Select all

convert toes.jpg -crop 100x100+0+0 toes_c1.jpg
Image

Code: Select all

convert toes.jpg -crop 100x100+50+50 toes_c2.jpg
Image
Giving X and Y offsets hasn't resized.

You are doing a crop after a resize. The offsets are in terms of the image after it has been resized.
snibgo's IM pages: im.snibgo.com
feanoro
Posts: 3
Joined: 2017-08-16T02:12:59-07:00
Authentication code: 1151

Re: Moving the crop position inside windows in collage

Post by feanoro »

Can you please post the same method using my code? This doesn't work with resize apparently.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Moving the crop position inside windows in collage

Post by snibgo »

My test image is smaller than yours, so the code is different.

Code: Select all

convert toes.jpg -resize 50% -crop 50x50+0+0 toes_c3.jpg
Image

Code: Select all

convert toes.jpg -resize 50% -crop 50x50+25+25 toes_c4.jpg
Image
(EDIT: I should, of course, "+repage" after cropping. This doesn't affect these simple examples.)
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving the crop position inside windows in collage

Post by fmw42 »

I do not understand what you want to do. If you move the images in your example, they will overlap each other. If that is what you want to do, then create a background image (white) the size you want. Then composite the image in the places you want rather than appending. Something like

Code: Select all

convert -size WxH xc:white \
\( image1 do your resize and crop \) \ -geometry +X1+Y1 -compose over -composite \
\( image2 do your resize and crop \) \ -geometry +X2+Y2 -compose over -composite \
result
Use WxH as your desired output image size. Do your resize and crop as you wrote in your original post. Supply X1 and Y1 for the offsets where you want the first image placed in the background. Do the same for image2 with X2 and Y2.

See
http://www.imagemagick.org/Usage/layers/#convert

If this is not what you want, please clarify. If this is what you want and you need more help, then provide your two input images.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving the crop position inside windows in collage

Post by fmw42 »

One other option is simply to use +smush -X to move the two images closer or +X to move them further apart horizontally. ( change to -smush to move them up or down). See http://www.imagemagick.org/script/comma ... .php#smush

Code: Select all

convert logo: rose: -gravity center -background gray +smush +20 logo_rose_smush_p20.jpg
Image

Code: Select all

convert logo: rose: -gravity center -background gray  +smush -20 logo_rose_smush_m20.jpg
Image

Change the -gravity and -background as desired.

Afterwards you can use -extent to enlarge the background area with whatever background color you want so that the result has the size you want.
See http://www.imagemagick.org/Usage/crop/#extent
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Moving the crop position inside windows in collage

Post by fmw42 »

If all you want to do is change the crop locations in your code, then in Windows syntax with new lines for easier reading, do

Code: Select all

convert 
( "1.jpg" -resize x2322 -gravity center -crop 1500x2322+X1+Y1 +repage ^
-gravity east -background white -splice 10x0 ) ^
( "2.jpg" -resize x2322 -gravity center -crop 1500x2322+X2+Y2 +repage ) ^
+append -bordercolor white -border 20 result.jpg
where X1,Y1 is the pixel offset from the center where you want the crop to take place for 1.jpg and similarly for 2.jpg. Positive values move right and down, negative values move up and left for the crop location. See http://www.imagemagick.org/Usage/crop/

or as one long line

Code: Select all

convert ( "1.jpg" -resize x2322 -gravity center -crop 1500x232+X1+Y1 +repage -gravity east -background white -splice 10x0 ) ( "2.jpg" -resize x2322 -gravity center -crop 1500x2322+X2+Y2 +repage ) +append -bordercolor white -border 20 result.jpg
Post Reply