Transparent bg + drop shadow + trim does not trim out transparent pixels
Posted: 2016-12-08T01:05:17-07:00
The color that -trim cuts out seems to be of a higher color depth than the output's, and therefore leaves in colors that in the output will be the same as the corner pixels onced rounded down to the output's color depth. How do I reduce the bit depth of ImageMagick's buffer so that -trim works based on the bit depth of the output? -depth seems to alter only the bit depth of the output, but not ImageMagick's internal buffer.
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.
That command does this:
Getting pixel enumeration, by appending txt: >out.txt to the command above, reveals the disparity between ImageMagick's image buffer and the output:
So ImageMagick's image buffer is 16 bit per channel, whereas I am exporting to 8 bit per channel. The pixel 487,0 is not 100% transparent in 16 bit but it becomes so in 8 bit. How do I get -trim to look at the image in 8 bit.
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)