Re: How to create drop shadow on resized image with an extension?
Posted: 2019-09-28T23:45:44-07:00
You have to adjust the computations of the offsets for the size of the input image.
# get the dimension of the input
1024x820 <-- landscape
# 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
Works for me!
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
88x70
xoffset = (100-88)/2 - 1 = 5
yoffset = (100-70)/2 - 1 = 15
Or even save the resized image and use it later
88x70
xoffset = (100-88)/2 - 1 = 5
yoffset = (100-70)/2 - 1 = 15
If using ImageMagick 7, then this works for landscape or portrait
# 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