Distingish alphatransparent pixels in PNGs
[email protected] (double) Tue, 20 Jul 2010 18:18:05 +0200
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello,
Is there a chance to distinguish alphatransparent pixels from simple
transparent pixels in PNGs? More precisely, is there a chance to check,
wheater a PNG uses alphatransparent pixels or not?
The down below testcase reports alphatransparent pixels, even if the
source file has only 1bit transparency.
Thanks a lot
Marcus
#include <stdio.h>
#include <stdlib.h>
#include <gd.h>
int main( int argc, char *argv[] )
{
system( "wget -O /tmp/test.png http://doppelbauer.name/test.png" );
FILE *fp = fopen( "/tmp/test.png", "r" );
gdImagePtr image = gdImageCreateFromPng( fp );
fclose( fp );
int x, y;
for( x=0; x < gdImageSX(image); ++x )
{
for( y=0; y < gdImageSY(image); ++y )
{
int color = gdImageGetPixel(image, x, y);
int alpha = gdImageAlpha(image,color);
if( alpha == 0 || alpha == gdTransparent )
continue;
printf( "PNG with 1bit alpha channel contains
alphatransparent pixel\n" );
return 0;
}
}
return 0;
}