Page 1 of 1

convert & resize & crop & composite : unexpected results

Posted: 2017-08-18T01:09:00-07:00
by 32d2d7ee
I have made a compositie of three images. This works fine!

Image
Command used:

Code: Select all

magick convert -units PixelsPerInch -size 2362x3543 xc:white 
( ADH_20170808_5539.jpg -auto-orient -resize 2362x )  -geometry +0+0 -composite 
( ADH_20170808_5578.jpg -auto-orient -resize 1175x )  -geometry +0+1777 -composite 
( ADH_20170808_5619.jpg -auto-orient -resize 1175x )  -geometry +1187+1777 -composite  -density 300 Sample_no_crop.jpg
Due to the camera aspect ratio the size of the image becomes: 2362x1575.
However my specs say that the top image should have the size 2362x1766, so I have to resize and crop.
On a single image I used this command and it works perfect. I get the right results.

Code: Select all

magick convert ADH_20170808_5539.jpg -auto-orient -resize "2362x1766^" -gravity Center -crop 2362x1766+0+0 +repage crop_image.jpg
Then I integrated this command in the first command:

Code: Select all

magick convert -units PixelsPerInch -size 2362x3543 xc:white 
( ADH_20170808_5539.jpg -auto-orient -resize "2362x1766^" -gravity Center -crop 2362x1766+0+0 +repage  )  -geometry +0+0 -composite 
( ADH_20170808_5578.jpg -auto-orient -resize "1175x1766^" -gravity Center -crop 1175x1766+0+0 +repage  )  -geometry +0+1777 -composite 
( ADH_20170808_5619.jpg -auto-orient -resize "1175x1766^" -gravity Center -crop 1175x1766+0+0 +repage  )  -geometry +1187+1777 -composite  -density 300 Sample_crop.jpg
This results in:
Image
Issue: the image is not generated as expected?

Question: What am I doing wrong?
What would be the right command?

Re: convert & resize & crop & composite : unexpected results

Posted: 2017-08-18T06:31:43-07:00
by snibgo
"-composite" respects the gravity setting. See http://www.imagemagick.org/script/comma ... s.php#crop

Your first command had no gravity setting, so it is undefined, which is similar (but not identical) to "-gravity NorthWest".

Re: convert & resize & crop & composite : unexpected results

Posted: 2017-08-18T09:45:45-07:00
by fmw42
User snibgo has a good point. I would add that some settings inside parentheses "leak" outside and so your composite commands are probably getting -gravity center. If that is the case, you can fix that by adding -gravity northwest before -geometry on each command. Or perhaps by adding -respect-parenthesis -gravity northwest right after convert.

Re: convert & resize & crop & composite : unexpected results

Posted: 2017-08-18T13:28:36-07:00
by snibgo
I would do it like this (with whatever your shell needs for line continuation and escapes). In the first command, insert "-gravity NorthWest". Does it do what you want?

Code: Select all

magick convert 
-units PixelsPerInch -size 2362x3543 xc:white 
-gravity NorthWest
( ADH_20170808_5539.jpg -auto-orient -resize 2362x ) -geometry +0+0 -composite 
( ADH_20170808_5578.jpg -auto-orient -resize 1175x ) -geometry +0+1777 -composite 
( ADH_20170808_5619.jpg -auto-orient -resize 1175x ) -geometry +1187+1777 -composite -density 300 
Sample_no_crop.jpg

In the second command, you want to switch between "NorthWest" and "Center", so I would do that explicitly.

Code: Select all

magick convert 
-units PixelsPerInch -size 2362x3543 xc:white 
( ADH_20170808_5539.jpg -auto-orient -resize "2362x1766^" -gravity Center -crop 2362x1766+0+0 +repage ) 
-gravity NorthWest -geometry +0+0 -composite 
( ADH_20170808_5578.jpg -auto-orient -resize "1175x1766^" -gravity Center -crop 1175x1766+0+0 +repage ) 
-gravity NorthWest -geometry +0+1777 -composite 
( ADH_20170808_5619.jpg -auto-orient -resize "1175x1766^" -gravity Center -crop 1175x1766+0+0 +repage ) 
-gravity NorthWest -geometry +1187+1777 -composite -density 300 
Sample_crop.jpg

Re: convert & resize & crop & composite : unexpected results

Posted: 2017-08-19T03:02:04-07:00
by 32d2d7ee
Thanks lot!
Indeed it was the missing -gravity NorthWest which caused the images to appear at the "wrong" place.