# get the dimension of the input
Code: Select all
convert 4x5.jpg -format "%wx%h" info:
# use the dimensions with size 88 to compute the resized dimensions and then the offsets
new width = 88
new height = 88*height/width = 88*820/1024 = 70
xoffset = (100-88)/2 - 1 = 5
yoffset = (100-70)/2 - 1 = 14
Code: Select all
convert 4x5.jpg -resize 88x88 ^
( +clone -background black -shadow 63x3+5+5 ) ^
+swap -background none -layers merge +repage ^
-background "#c2c5cc" -layers flatten +repage ^
( -size 100x100 xc:"#c2c5cc" ) ^
+swap -gravity northwest -geometry +5+14 -compose over -composite ^
4x5_result.png
If portrait, then
new height = 88
new width = 88*width/height
etc.
Alternately, you can do the resize to get the new dimenions and not have to worry about portrait or landscape
Code: Select all
convert 4x5.jpg -resize 88x88 -format "%wx%h" info:
xoffset = (100-88)/2 - 1 = 5
yoffset = (100-70)/2 - 1 = 15
Code: Select all
convert 4x5.jpg -resize 88x88 ^
( +clone -background black -shadow 63x3+5+5 ) ^
+swap -background none -layers merge +repage ^
-background "#c2c5cc" -layers flatten +repage ^
( -size 100x100 xc:"#c2c5cc" ) ^
+swap -gravity northwest -geometry +5+15 -compose over -composite ^
4x5_result.png
Or even save the resized image and use it later
Code: Select all
convert 4x5.jpg -resize 88x88 +write 4x5_resize.png -format "%wx%h" info:
xoffset = (100-88)/2 - 1 = 5
yoffset = (100-70)/2 - 1 = 15
Code: Select all
convert 4x5_resize.png ^
( +clone -background black -shadow 63x3+5+5 ) ^
+swap -background none -layers merge +repage ^
-background "#c2c5cc" -layers flatten +repage ^
( -size 100x100 xc:"#c2c5cc" ) ^
+swap -gravity northwest -geometry +5+15 -compose over -composite ^
4x5_result.png
If using ImageMagick 7, then this works for landscape or portrait
Code: Select all
magick 4x5.jpg -resize 88x88 \
-set option:xoffset "%[fx:floor((100-w)/2-1)]" ^
-set option:yoffset "%[fx:floor((100-h)/2-1)]" ^
( +clone -background black -shadow 0x3+5+5 ) ^
+swap -background none -layers merge +repage ^
-background "#c2c5cc" -layers flatten +repage ^
( -size 100x100 xc:"#c2c5cc" ) ^
+swap -gravity northwest -geometry "+%[xoffset]+%[yoffset]" -compose over -composite ^
4x5_result.png