I've got some PNG images with transparency, and I need to create versions with the image layer composed onto a white background. I've tried various things with Image Magick "convert" operations, but either nothing happens at all or I get an error. I don't want to go to an intermediate JPG form because I don't want the artifacts. Of course it's easy to do this in Gimp or Photoshop or whatever, but I'd really rather script it from the command line because there are many of these things.
An example of a non-working Image Magick command is:
convert img1.png -background white -flatten img1-white.png
That results in an error.
Thanks!
I needed either: both
-alpha background
and-flatten
, or-fill
.I made a new PNG with a transparent background and a red dot in the middle.
convert image.png -background green -alpha off green.png
failed: it produced an image with black backgroundconvert image.png -background green -alpha background -flatten green.png
produced an image with the correct green background.Of course, with another file that I renamed
image.png
, it failed to do anything. For that file, I found that the color of the transparent pixels was "#d5d5d5" so I filled that color with green:convert image.png -fill green -opaque "#d5d5d5" green.png
replaced the transparent pixels with the correct green.To actually remove the alpha channel from the file, use the alpha off option:
It's -alpha off, NOT -alpha remove! iOS app store upload fails when there is an alpha channel in any icon!!
Here's how to do it: mogrify -alpha off *.png
This is not exactly the answer to your question, but I found your question while trying to figure out how to remove the alpha channel, so I decided to add this answer here:
If you want to remove alpha channel using imagemagick, you can use this command:
here's how to replace the same image in all folders in a directory with white instead of transparent:
mogrify -background white -flatten */*.png
this creates an image just placing the 1st with transparency on top of the 2nd
originally found the tip on this post