conversion to png will make black pixels transparent

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
supervhs
Posts: 4
Joined: 2010-10-25T00:31:34-07:00
Authentication code: 8675308

conversion to png will make black pixels transparent

Post by supervhs »

I convert a very simple xpm to png. The image is a solid black box.

Code: Select all

convert blackbox.xpm blackbox.png
The converted png image only contains a transparent background. Nothing more. The black color becomes transparent.
If i change the color of my box to red, green blue or any other color or even almost pure black like #000001 it will convert fine.
But if the value is black/#000000 it will become transparent.

I see this problem with ImageMagick-6.6.7-5, ImageMagick-6.6.7-9
Problem does not exist in ImageMagick-6.6.4-8

Content in xpm file:

Code: Select all

const char *black_box[] = {
/* columns rows colors chars-per-pixel */
"16 16 2 1",
"  c None",
"0 c #000000",
// Pixels
"                ",
"                ",
"                ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"   00000000000  ",
"                ",
"                "};
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: conversion to png will make black pixels transparent

Post by glennrp »

The problem is that " " resolves to transparent black and 0 resolves to black
The PNG encoder sometimes has difficulty
telling the difference between black and transparent black, and
thinks it can use the "cheap transparency" feature of PNG.
Unfortunately this turns both blacks into transparent black.

This is fixed in SVN r3729 and will be in IM-6.6.7-10.

We have to force such images to
use color-type 3 (indexed-color) or color-type 4 (Gray-Alpha)
instead of color-type 0 Grayscale with a specified transparent
color.

This unfortunately requires an additional scan of the pixels
or the colormap to make sure that there is a single
transparent color, and no opaque color has the same
RGB components (as in your example), and no semi-transparent
colors, and to not try to use PNG's "cheap transparency" when
these criteria aren't met.
Post Reply