16

I'm having a problem with how Photoshop handles completely-transparent pixels when exporting as PNG, which is that the red, green, and blue color channels of any completely-transparent pixels are saved as 0 instead of the color that I define in Photoshop.

For example: I have a PSD file with a layer mask. Some colored portions of the image are made completely transparent by the layer mask, but I still want the original color channels to be written to the PNG file instead of just 0.

(Yes, the PNG format itself does contain RGB data even for fully-transparent pixels. This is a problem with Photoshop, not PNG.)

If you're wondering why having color data matters when a pixel is completely transparent, then here are a couple of use cases:

  • The PNG is being sampled at a higher resolution than it is saved as and the sampled values are interpolated between neighboring pixels. This can result in a faint black "halo" around the image if the interpolation isn't weighted by transparency. (In my case, this up-sampling is being done on the GPU, which for performance reasons does not weigh by transparency.)
  • The red, green, blue, and alpha channels in the PNG file are being used for purposes other than storing color information. (In my case, I use all four channels to store data needed for real-time lighting computations.)

Thanks for your help!

EDIT

I'm going to try to explain the problem I'm having with use of some visual aids. Showing transparent things is hard, but hopefully this makes my problem clearer:

I have a PSD file with one layer and a layer mask. The color layer looks like this:

enter image description here

Its layer mask looks like this:

enter image description here

If I export this PSD file as a PNG, I get this:

enter image description here

(The white regions are indeed transparent; they just look white against the white background.)

You may be wondering: What's the problem? That looks right! Well, the problem is with the color information stored in those transparent pixels. Using a tool to strip out the opacity data from the PNG while leaving the RGB intact, we can see the color information that Photoshop saves to the transparent pixels:

enter image description here

As you can see, Photoshop has replaced the color information in the transparent pixels with black. Whereas, with the opacity data removed from the PNG, I want it to look exactly like the original color layer:

enter image description here

14
  • Showing an example of what you are experiencing might be more helpful. Mainly because, there should not be any color information in the transparent portion of the PNG. How are you saving out the PNG? Are you using "Save for Web" and do you have the "transparency" checked? I know it sounds basic but not sure how you are getting your results.
    – ErickP
    Commented Nov 30, 2015 at 16:21
  • Yeah, I didn't post any example images because you can't actually see the issue (without loading the PNG in a paint program and turning off the transparency), since the issue is only with pixels that are completely transparent. I'll see if I can come up with a way to visualize what I'm talking about.
    – Walt D
    Commented Nov 30, 2015 at 16:39
  • But when you say "there should not be any color information in the transparent portion of the PNG", I actually want there to be color information in the transparent portion of the PNG. I know that sounds wierd, but there are certain applications, such as the two I've mentioned above. (And yes, PNG totally supports color information in its transparent regions; I use it all the time in procedurally-generated PNGs. The issue is with how Photoshop saves transparent regions to PNGs.)
    – Walt D
    Commented Nov 30, 2015 at 16:42
  • 1
    @DA01 I don't think it's a bug as much as it's an optimzation that Photoshop does (PNGs with uniform colors take less disk space) that is breaking my particular use case.
    – Walt D
    Commented Nov 30, 2015 at 18:14
  • 1
    @ErickP Thanks for trying to help, I really appreciate it. :) Thankfully, GPUs are pretty standard these days, and this kind of upscaling (known as bilinear interpolation) works exactly the same across all of them, so whatever solution I do eventually find should work universally.
    – Walt D
    Commented Nov 30, 2015 at 18:50

1 Answer 1

13

I found a solution! The SuperPNG plugin will preserve the RGB values for transparent pixels as long as you leave the "Clean Transparent" option unchecked.

4
  • I'm curious if there is a Photoshop CC equivalent to SuperPNG? Commented Jul 26, 2017 at 15:04
  • 1
    It is worth noting that SuperPNG seems to work fine with Photoshop CC.
    – Wouter
    Commented Feb 17, 2022 at 14:59
  • For the record, newer versions of Photoshop do not seem to automatically destroy transparent color data when saving. However, far worse, newer versions of photoshop destroy color data when the image is manipulated or modified, such as painting or resizing. Because of this, SuperPNG will not resolve the issue if you are doing any type of modification inside Photoshop. Unfortunately, there does not seem to be a solution for this.
    – Robert
    Commented Jan 1, 2023 at 19:38
  • Sorry, have to make a correction. Apparently I do not know how to use SuperPNG correctly. At first glance, I thought it was an export tool only, but if you hold shift while opening PNG files, it will open a dialog to allow you to store alpha as a separate channel while editing in Photoshop. As long as the document is edited in this way, the color data should be preserved. Thanks a bunch to Walt D for the solution.
    – Robert
    Commented Jan 1, 2023 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.