11

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

  • 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 Nov 30 '15 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 Nov 30 '15 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 Nov 30 '15 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 Nov 30 '15 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 Nov 30 '15 at 18:50
9

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.

  • I'm curious if there is a Photoshop CC equivalent to SuperPNG? – Marcel Wilson Jul 26 '17 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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