2

It appears that PNG files contain background color information for transparent pixels. This sometimes becomes noticeable when using that image as a texture with wrong settings.

How to find out in Linux (ideally command line) what the color of the transparent pixels in a PNG file is?

3

The background color is conveyed via the PNG "bKGD" chunk.

From the command line, you can use "pngcheck -v". Download and install pngcheck from

http://www.libpng.org/pub/png/apps/pngcheck.html

then type

pngcheck -v file.png

If a bKGD chunk is present in the PNG file, pngcheck's output will include something like this:

chunk bKGD at offset 0x000a0, length 6 red = 0x00e0, green = 0x00e0, blue = 0x0080

You probably already have ImageMagick (version 6.6.9 or later), so you could also obtain bKGD chunk information, along with a lot of other stuff, by typing

identify -verbose file.png

and look for

Background color: srgba(224,224,128,1)

png:bKGD: chunk was found (see Background color, above)

If only "Background color" appears but not "png:bKGD:...", then identify is reporting ImageMagick's default background color and no bKGD chunk is present in the PNG file.

|improve this answer|||||
  • Thanks! identify is more readable, more widely available and pngcheck doesn't seem to show that info for grayscale images: codepad.org/2yquVHrc – qubodup May 15 '15 at 12:16
  • I don't think that has anything to do with the image being grayscale, just that it lacks a bKGD chunk (which is an optional chunk!). ImageMagick will show a background color because ImageMagick assumes a default background color if there is none in the PNG file. I'll update the answer. – Glenn Randers-Pehrson May 15 '15 at 13:58
0

The PNG specification (link) describes the tRNS chunk where transparency information is stored.

The software library libpng can read and write PNG files, including the transparency information. Specifically, look up the following function:

png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans, &trans_color)
|improve this answer|||||
  • Thank you. Unfortunately I can't program on that level, which is why I chose superuser and not stackoverflow superuser.com/help/on-topic – qubodup May 14 '15 at 0:55

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.