[SOLVED] Flatten image onto white but keep alpha channel
Posted: 2016-10-14T11:59:01-07:00
I have a bunch of png files with transparency which are premultiplied with black.
I need them to be composited on white but preserve the alpha channel for converting to webp format.
If I don't do that I get a black edge where there are semi transparent pixels.
Is there a simple command that can composite an image onto white but preserve the alpha channel?
I've found that this does the first part nicely and correctly handles the premultiplied alpha
magick source.png -background white -alpha remove out.png
but how do you preserve the alpha channel during the operation?
Is the only way to do it to copy it out into a file first and then composite it back, i.e using 3 operations
Can it be done in one?
Another approach would be to unmultiply the alpha but I can't seem to find anything in magick that will do that.
If it helps this is the full set of steps that I'd like to reduce if possible
magick -alpha extract source.png mask.png
magick source.png -background white -alpha remove flatten.png
magick flatten.png mask.png -alpha off -compose copy_opacity -composite -background white -alpha background final.png
I need them to be composited on white but preserve the alpha channel for converting to webp format.
If I don't do that I get a black edge where there are semi transparent pixels.
Is there a simple command that can composite an image onto white but preserve the alpha channel?
I've found that this does the first part nicely and correctly handles the premultiplied alpha
magick source.png -background white -alpha remove out.png
but how do you preserve the alpha channel during the operation?
Is the only way to do it to copy it out into a file first and then composite it back, i.e using 3 operations
Can it be done in one?
Another approach would be to unmultiply the alpha but I can't seem to find anything in magick that will do that.
If it helps this is the full set of steps that I'd like to reduce if possible
magick -alpha extract source.png mask.png
magick source.png -background white -alpha remove flatten.png
magick flatten.png mask.png -alpha off -compose copy_opacity -composite -background white -alpha background final.png