Instead of a 3-3-2 'posterize' palette, could you not just do a -colors 256
By default that generates both transparent and semi-transparnt colors.
EG for PNG8 just do -colors 256
with no other settings or alpha thresholding.
GIF however does some special handling for color reduction as it only wants a single boolean full-transparency color.
Specifically it alpha thresholds, and uses a -quantize transparency setting before color reduction to 255 colors when a transparent color is present after the threshold (256 colors if no transprency).
EG the psuedo code for GIF should be following...
Code: Select all
-channel A -threshold 50%
if (fully-)transparent pixels are present it then...
-quantize transparent -colors 255
otherwise if no transparent pixels present...
-colors 256
Of course -colors should short-circuit if less than the requested number of colors is present.