FAQ
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;
}

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
groupphp-gd-devel @
categoriesphp
postedJul 20, '10 at 4:18p
activeJul 21, '10 at 9:42a
posts2
users2
websitephp.net

2 users in discussion

Pierre Joye: 1 post Double: 1 post

People

Translate

site design / logo © 2021 Grokbase