I am trying to apply a drop shadow to non-square images on a transparent canvas (say, a solid circle on a transparent canvas), and then trimming out all transparent pixels before outputting. But -trim leaves in some pixels around the drop shadow that in the output are 100% transparent, seemingly due to them not being completely so while still inside ImageMagick. I know I could use -fuzz to get approximate results, but I need -trim to be 100% accurate, not fuzzy.
Code: Select all
convert "input.png" \
\( "input.png" -alpha extract \) \
-matte -bordercolor none -border 100x100 \
-alpha off -compose copy_opacity -composite -compose over \
\( -clone 0 -background black -shadow 25x4+3+4 \) \
+swap \
-background none -layers merge \
-trim \
"output.png"
- expands the canvas to give the drop shadow a bit of room
- creates a drop shadow from the alpha
- places the drop shadow under the original image
- and finally trims out transparent pixels.
Getting pixel enumeration, by appending txt: >out.txt to the command above, reveals the disparity between ImageMagick's image buffer and the output:
Code: Select all
# ImageMagick pixel enumeration: 522,322,65535,srgba
0,0: (0,0,0,0) #00000000 none
[…]
487,0: (0,0,0,1) #00000000 srgba(0,0,0,1.5259e-05)