What color becomes a transparent area when saved to a non-alpha format?
Moderators: XnTriq, helmut, xnview, Dreamer
-
- Posts: 114
- Joined: Fri Oct 25, 2013 4:55 pm
What color becomes a transparent area when saved to a non-alpha format?
Hi Pierre,
I have a bunch of PNGs which need to become JPGs. Many of these PNGs have transparent areas.
JPG doesn't know transparency, so the transparent areas must be colored somehow.
Could you please explain the algorithm used to decide which color is used?
I have some PNGs the transparent background becomes white, others where the transparent background becomes black.
And even more strange is that when you add text during batch convert, you'll get JPG where some parts of the background become black and others become white. Attached is a sample which is completely messed up.
Regads
Dietmar
I have a bunch of PNGs which need to become JPGs. Many of these PNGs have transparent areas.
JPG doesn't know transparency, so the transparent areas must be colored somehow.
Could you please explain the algorithm used to decide which color is used?
I have some PNGs the transparent background becomes white, others where the transparent background becomes black.
And even more strange is that when you add text during batch convert, you'll get JPG where some parts of the background become black and others become white. Attached is a sample which is completely messed up.
Regads
Dietmar
You do not have the required permissions to view the files attached to this post.
Last edited by dietmar on Mon Mar 12, 2018 12:55 pm, edited 1 time in total.
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
could you post one of each?dietmar wrote: I have some PNGs the transparent background becomes white, others where the transparent background becomes black.
do you use alpha for text?And even more strange is that when you add text during batch convert, you'll get JPG where some parts of the background become black and others become white. Attached is a sample which is completely messed up.
Pierre.
-
- Posts: 114
- Joined: Fri Oct 25, 2013 4:55 pm
Re: What color becomes a transparent area when saved to a non-alpha format?
Pierre,xnview wrote: could you post one of each?
if you take the PNG from my original post, you'll see that the top and bottom parts become black while the center parts become white. If I remember correctly, this is how I had the image in GIMP before making the outer region transparent.
Thus it looks as if this information is still in the PNG and that you simply remove the alpha channel. Might this be? If I remove the alpha channel in GIMP, I'll get a white background, though.
Attached are two small PNGs with transparency in their top right corners. Take each and Convert To JPEG. One background becomes black, the other becomes white.
I had used the Text option in Batch Convert. Text opacity 70%, color gray, no border, no fill, no outline, shadow black.xnview wrote: do you use alpha for text?
In any case I would expect that the text get's added AFTER the transparency of the original image got lost.
Regards
Dietmar
You do not have the required permissions to view the files attached to this post.
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
If you check the picture without alpha channel, you can see that background is not the samedietmar wrote: if you take the PNG from my original post, you'll see that the top and bottom parts become black while the center parts become white. If I remember correctly, this is how I had the image in GIMP before making the outer region transparent.
Thus it looks as if this information is still in the PNG and that you simply remove the alpha channel. Might this be? If I remove the alpha channel in GIMP, I'll get a white background, though.
Attached are two small PNGs with transparency in their top right corners. Take each and Convert To JPEG. One background becomes black, the other becomes white.
there is an error in the conversion for jpeg, alpha channel is removed not merged...I had used the Text option in Batch Convert. Text opacity 70%, color gray, no border, no fill, no outline, shadow black.
In any case I would expect that the text get's added AFTER the transparency of the original image got lost.
you can add a 'convert depth'=> truecolor action
Pierre.
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
Thanks to your detailed description I can reproduce the problem.
Pierre.
-
- Posts: 114
- Joined: Fri Oct 25, 2013 4:55 pm
Re: What color becomes a transparent area when saved to a non-alpha format?
Which brings back my original question: "What color becomes a transparent area when saved to non-alpha format?"xnview wrote: Thanks to your detailed description I can reproduce the problem.
If you now correctly merge the alpha channel instead of removing it, there are still multiple options. Given a 100% transparent area as in my examples, saving to a non-alpha-capable format such as JPEG, you need to decide on a background color. You cannot use a background "behind" the completely transparent area as in my PNGs since the user may not even know that there is one. So should a 100% transparent area become white (or black or red or checkered)? In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
Kind regards
Dietmar
-
- Moderator & Librarian
- Posts: 6374
- Joined: Sun Sep 25, 2005 3:00 am
- Location: Ref Desk
Re: What color becomes a transparent area when saved to a non-alpha format?
I support Dietmar's request.dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
Isn't better to use 'change color depth', and add a background color (when converting in 24bits)?XnTriq wrote:I support Dietmar's request.dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
Pierre.
-
- Posts: 114
- Joined: Fri Oct 25, 2013 4:55 pm
Re: What color becomes a transparent area when saved to a non-alpha format?
Could be. GIMP has a simple function called 'remove alpha channel'. But this also requires the user to select a background color - GIMP's standard background color in this case.xnview wrote:Isn't better to use 'change color depth', and add a background color (when converting in 24bits)?XnTriq wrote:I support Dietmar's request.dietmar wrote:In my opinion there should be an option somewhere (file format settings maybe?) to let the user select a background color for transparent images.
Maybe XNVIEW should also have a selectable 'standard background color'. The draw function has a background color, the rotate function has a background color, the remove alpha channel needs one. Maybe you can place the foreground/background color selection at a more prominent place, e.g. the toolbar, and use the current setting for all functions which need a background color.
Regards
Dietmar
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
i means in batch convert?
Pierre.
-
- Posts: 114
- Joined: Fri Oct 25, 2013 4:55 pm
Re: What color becomes a transparent area when saved to a non-alpha format?
'Change color depth' has the same options in batch convert as in dialog. So a background color selection would be needed for both.xnview wrote:i means in batch convert?
I'm not sure if an ordinary user will understand that saving as JPG implicitly does Change Color Depth to 24-bits, though.
Regards
Dietmar
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
-
- Posts: 10
- Joined: Sat Feb 03, 2018 9:07 am
Re: What color becomes a transparent area when saved to a non-alpha format?
How much do you lose, if instead of the range for printing 0 ~ 255 get 0 ~ 254 or 1 ~ 255? especially when you consider that in a number of printers there is white ink that will print white as "white" color! From that, transparency is needed! What do we do for this? we shift the brightness of the entire picture to +1 or -1 and crop the image by an alpha channel or a template file, assigning a transparent black color for the printers, which is printed for white, and white for all others (will printers print a 1% point? inks, that is not present and this color will remain white, and for RGB, this is 254-254-254). Then again we shift the picture, but already in the opposite direction to the lightness, when our file is saved with transparency.
And you can, not move everything, but only replace all the colors 255-255-255. 254-255-255, 255-254-255 and 255-255-254 at 254-254-254, and then what you need to mask assign as 255-255-255, and exactly the opposite, when we do it in black .
This decision, which was applied in practice. To implement it, you need to add an option to add an image to the mask template, i.e. crop and make a certain area transparent if it is * .png or index the colors and assign a transparent color to * .jpg, which is excluded by the alpha channel or mask by the shift method that I described above, but then you need to store and template files - binary or in GrSc, like * .png
In order not to shift the entire range of tones by levels, you can apply the HALD CLUT and change only the white or black color.
*- [ coment ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.bat - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nconvert -icc_bcp -icc_intent 1 -icc_in "C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" -icc_out"C:/Windows/System32/spool/drivers/color/sRGB2014.icc" -dpi 300 [Levels input 255 to 254] -replace 0 0 0 1 1 1 [Mask to img, color W] -replace 255 255 255 0 0 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.xbs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<?xml version="1.0" encoding="UTF-8"?><XnView_script version="1.0" name="Mask_to_iImage">
<ICC_convert input_profile="C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" output_profile="C:/Windows/System32/spool/drivers/color/sRGB2014.icc" rendering="1" ignore_embedded="false" black_compensation="true" active="false"/>
<Set_DPI x="300" y="300" keep="false" active="false"/>
<Levels in_low="0,0,0,0," in_high="255,255,255,255," out_low="0,0,0,0," out_high="254,255,255,255," gamma="1,1,1,1," mode="0"/>
<Replace_color src_color="#000000" dst_color="#010101" tolerance="1"/>
<Add_mask filename="D:/Docs/Downloads/XnViewMP-win-x64/Version090/AddOn/Masks/S-2018-Alfa_MaskP.png" color="#ffffff" opacity="100" blur="false" stretch="true" usealpha="false"/>
<Replace_color src_color="#ffffff" dst_color="#000000" tolerance="0"/>
<Output folder="" filename="{Filename}_1" case="0" startIndex="1" format="PNG">
<Options overwrite="1" orgDate="false" keepMeta="true" keepICC="true" keepFolder="false" keepParentFolder="false" delOrg="false" multipage="false" allPages="false" openExplorer="false" openBrowser="false" clearItems="false"/>
<PNG level="0" interlaced="false" filter="0"/>
</Output>
</XnView_script>
And you can, not move everything, but only replace all the colors 255-255-255. 254-255-255, 255-254-255 and 255-255-254 at 254-254-254, and then what you need to mask assign as 255-255-255, and exactly the opposite, when we do it in black .
This decision, which was applied in practice. To implement it, you need to add an option to add an image to the mask template, i.e. crop and make a certain area transparent if it is * .png or index the colors and assign a transparent color to * .jpg, which is excluded by the alpha channel or mask by the shift method that I described above, but then you need to store and template files - binary or in GrSc, like * .png
In order not to shift the entire range of tones by levels, you can apply the HALD CLUT and change only the white or black color.
*- [ coment ]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.bat - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
nconvert -icc_bcp -icc_intent 1 -icc_in "C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" -icc_out"C:/Windows/System32/spool/drivers/color/sRGB2014.icc" -dpi 300 [Levels input 255 to 254] -replace 0 0 0 1 1 1 [Mask to img, color W] -replace 255 255 255 0 0 0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *.xbs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<?xml version="1.0" encoding="UTF-8"?><XnView_script version="1.0" name="Mask_to_iImage">
<ICC_convert input_profile="C:/WINDOWS/system32/spool/drivers/color/AdobeRGB1998.icc" output_profile="C:/Windows/System32/spool/drivers/color/sRGB2014.icc" rendering="1" ignore_embedded="false" black_compensation="true" active="false"/>
<Set_DPI x="300" y="300" keep="false" active="false"/>
<Levels in_low="0,0,0,0," in_high="255,255,255,255," out_low="0,0,0,0," out_high="254,255,255,255," gamma="1,1,1,1," mode="0"/>
<Replace_color src_color="#000000" dst_color="#010101" tolerance="1"/>
<Add_mask filename="D:/Docs/Downloads/XnViewMP-win-x64/Version090/AddOn/Masks/S-2018-Alfa_MaskP.png" color="#ffffff" opacity="100" blur="false" stretch="true" usealpha="false"/>
<Replace_color src_color="#ffffff" dst_color="#000000" tolerance="0"/>
<Output folder="" filename="{Filename}_1" case="0" startIndex="1" format="PNG">
<Options overwrite="1" orgDate="false" keepMeta="true" keepICC="true" keepFolder="false" keepParentFolder="false" delOrg="false" multipage="false" allPages="false" openExplorer="false" openBrowser="false" clearItems="false"/>
<PNG level="0" interlaced="false" filter="0"/>
</Output>
</XnView_script>
You do not have the required permissions to view the files attached to this post.
-
- Posts: 10
- Joined: Sat Feb 03, 2018 9:07 am
Re: What color becomes a transparent area when saved to a non-alpha format?
result with indexed colors, where black is assigned transparent and with an alpha channel in RGB.
!To ensure that the final file does not have a white edge, in the place where the anti-aliasing was done, the mask should be binary in color.!
!To ensure that the final file does not have a white edge, in the place where the anti-aliasing was done, the mask should be binary in color.!
You do not have the required permissions to view the files attached to this post.
-
- Author of XnView
- Posts: 44490
- Joined: Mon Oct 13, 2003 7:31 am
- Location: France
Re: What color becomes a transparent area when saved to a non-alpha format?
This problem is supposed to be fixed in XnView MP 0.91. Please check and confirm the bug fix here.
Pierre.