New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different behaviour between PNG24 and PNG32 when using transparency mask #511
Comments
Your syntax is overly complex with unnecessary clones. Make your mask image (ThumbnailCreator200x200.png) white on black rather than black on transparent. Then simplify your commands. I am not sure why you get an transparent result with PNG24, since it should remove the alpha channel. So I have posted three versions for PNG24. The second explicitly removes the alpha channel with a black background. The third does the same with a white background. Here is my code. I have used PNG for the mask, but you can change that to mpc if you want.
I do not see the need to use explicit PNG24: or PNG32. You can just leave it off and the PNG writer will generally provide the correct result, especially if you have transparency already in your image. If you do not want the transparency, then just do -alpha off at the end. |
Your png32 results have alpha channels with semitransparent pixels (alpha neither 0 nor 1). I guess "convert" is having difficulty transforming that into PNG24 which all transparent pixels need to be fully transparent and all of them have to be the same color. Forcing them all to have the same underlying color helps. |
My gratitude to both of you for looking into this issue. @fmw42 - My apologies, the original command was very long, with multiple output images and even after removing the redundant stuff, some still got left out(clone and use of parentheses). Alas, I have to use the alpha channel. The examples that you have provided will only work if these images are displayed on a static background colour. However, at our platform, we use black, white and even a user specific cover image as the background for a profile picture. Thus choosing a static background colour(white or black) is not an option. @glennrp - You are right on the mark, this is due to anti-aliasing. I did notice that the circumference in PNG32 looks better than PNG24, but failed to correlate it with the current issue. Anti-aliasing would add values other than 0 or 1. I went ahead and turned anti-aliasing off when creating the alpha mask, however, this also fails with the few pixels within the circle area being turned transparent. @glennrp: I didn't fully understand the same color part in your comment.
Commands(broken further to separate square image generation with alpha masking):-
The result was same as the image uploaded at the start of the issue:- Edit - The 32-bit image was again fine. |
That's because the original has a few pixels that have the same underlying color (black, in this case) as the transparent pixels. You could make a first pass over the image to change those (something like |
@glennrp - Thank you so much. This is a good solution, I can just change all black color pixels to rgb(0,0,1) and the change which will be imperceptible to human eyes. For future users:-
This worked fine and created an 11.7% smaller image than the PNG32 counterpart. P.S. - @dlemstra - Shouldn't the issue be marked bug along with question tag? The commands in the first comment shouldn't replace pure Black pixels where alpha is Foreground. In case, if my understanding is incorrect, please do comment.
Thank you in advance. |
It's not a bug but simply a feature of the PNG format. When using the tRNS chunk with a PNG24 RGB image, all pixels of the color named in the tRNS chunk are transparent. |
Ohhh..., wasn't aware of how PNG24 stored the alpha mask. Thank you Glenn. |
The PNG Developers refer to that as "GIF-style transparency". It is used with PNG color-type 2 (RGB) and color-type 0 (grayscale). |
Hi,
I am working on a command for cropping 200x200 area from the center of any picture and then creating a circular image from the cropped image.
To increase speed, I pre-generate the alpha mask as below:-
convert -size 200x200 xc:none -fill black -draw "circle 100,100 1,100" -depth 8 mpc:ThumbnailCreator200x200.mpc
Next, I have used below commands, one for PNG32 and one for PNG24:-
I tried removing the following command options which sets any fully transparent pixel to the background colour, while leaving it fully-transparent.
-background rgb\(0,0,0\) -alpha Background
This resulted in attached images 4 and 5.
1 - Input Image
2 - PNG24 Image
3 - PNG32 Image
4 - PNG24 Image without resetting transparent pixels to the background colour.
5 - PNG32 Image without resetting transparent pixels to the background colour.
Thank you for looking into the issue and I appreciate any help you can provide.
Other info:-
IM is built from latest code as of yesterday to test.
Version: ImageMagick 7.0.6-0 Q16 x86_64 2017-06-12 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI
Delegates (built-in): bzlib fftw fontconfig freetype jng jpeg lcms lzma openexr pangocairo png tiff webp x xml zlib
The text was updated successfully, but these errors were encountered: