Replace transparency in PNG images with white background
Solution 1:
-background white -alpha remove -alpha off
Example:
convert image.png -background white -alpha remove -alpha off white.png
Feel free to replace white
with any other color you want. Imagemagick documentation says this about the -alpha remove
operation:
This operation is simple and fast, and does the job without needing any extra memory use, or other side effects that may be associated with alternative transparency removal techniques. It is thus the preferred way of removing image transparency.
Solution 2:
This works for me:
convert -flatten img1.png img1-white.png
Documentation references:
-flatten
command-line option-
-layers
command-line option (-flatten
is equivalent to-layers flatten
)
Solution 3:
Flattening image and applying background image is straight forward in ImageMagick
However, order of the commands is very important
To apply any background on a transparent image and flatten it, first apply the background than flatten it. The reverse doesn't work.
$ convert sourceimage.png -background BackgroundColor -flatten destinationimage.png
Solution 4:
The only one that worked for me was a mix of all the answers:
convert in.png -background white -alpha remove -flatten -alpha off out.png
Solution 5:
here's how to replace the same image in all folders in a directory with white instead of transparent:
mogrify -background white -flatten */*.png