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!
If you want to change the opacity of a smaller area than the entire PNG, you can select a rectangular area of the PNG and apply the opacity effect only in this region. The opacity region can be changed in the preview with your mouse or in the options using the left/right offsets and width/height parameters.
-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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With