![]() So, if you are converting several images at once, e.g. However this will not work with "mogrify" or with a sequence of multiple images, basically because the "-flatten" operator is really designed to merge multiple images into a single image. Included in that section is mention of an important caveat to the usage of -flatten as a technique for removing transparency: There are more details on other, often-used techniques for removing transparency described in the Removing Transparency from Images section. ![]() Thus, if you do not need the alpha channel you can make your output image size smaller by adding the -alpha off option, e.g: convert in.png -background white -alpha remove -alpha off out.png If you no longer need the alpha channel you can then use Alpha Off to disable it. Note that while transparency is 'removed' the alpha channel will remain turned on, but will now be fully-opaque. It is thus the prefered way of removing image transparency. ![]() 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. using the -background color of your choosing. The reference says this is more efficient and is the preferred method.The Alpha Remove section of the ImageMagick Usage Guide suggests using the -alpha remove option, e.g.: convert in.png -background white -alpha remove out.png We do not need the -alpha off mentioned in the reference, since JPG does not support any alpha channel. The result is the same as -background white -flatten. So starting with the original PNG, we do convert google.png -background white -alpha remove google_alpharemoveoff.jpg convert google_bg_white.png -flatten google_bg_white_flatten.jpgĪn alternate method to -flatten is to use -alpha remove, which is discussed. So one still needs to flatten the result, so that the antialiasing of the alpha channel will smoothly blend the colors near the boundaries. convert google_bg_white.png google_bg_white.jpg You have a nice clean background, but the image is still aliased (as it was in the original when the alpha channel was remove). ![]() However, if you simply remove the alpha channel the JPG will show aliasing since only the fully transparent pixels' background colors were changed to white. convert google.png -background white -alpha background google_bg_white.png It will look the very same as the original PNG. Often one will reprocess the original transparent PNG image so that it has some constant color underneath the alpha channel so that later one can remove the alpha channel and not have odd colors showing. Simple Flatten (default background is white): convert google.png -flatten google_flatten.jpgįlatten with black background: convert google.png -background black -flatten google_flatten_black.jpg The stripes are from the underneath color below the alpha channel.Īlpha Channel (nicely antialiased): convert google.png -alpha extract google_alpha.jpg Turn alpha off: convert google.png -alpha off google_aoff.jpg However, the background color you use will change the appearance in transparent areas from that of the underneath color. I know of no significant issues using -background xx -flatten when converting PNG or GIF to JPG. PNG allows 8-bit transparency (partial transparent). GIF only allows binary transparency - fully transparent or fully opaque. But you should specify -background somecolor before -flatten, if you do not want the default background color. So you should use -flatten to properly do that conversion. JPG does not allow transparency and any transparent areas will show what color is underneath the transparency, which is often black. The problem with converting PNG to JPG is when the PNG has transparency.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |