Re: [GD-DEVEL] Distingish alphatransparent pixels in PNGs

[email protected] (Pierre Joye) Wed, 21 Jul 2010 11:42:04 +0200
Newsgroups php.gd.devel
Message-ID <[email protected]>
hi,

Transparent pixel as in GIF or some PNG format have nothing to do with
the alpha channel (level of translucency). Transparent pixel is either
opaque or transparent and is defined by only one color (color value or
color index for palette images).

Alpha channels (PNG only) are about level of translucency.

Can you send the image please? So I can tell you which case applies.

Cheers,

On Tue, Jul 20, 2010 at 6:18 PM, double <[email protected]> wrote:
> 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[] )
> {
> =A0 =A0system( "wget -O /tmp/test.png http://doppelbauer.name/test.png" )=
;
>
> =A0 =A0FILE *fp =3D fopen( "/tmp/test.png", "r" );
> =A0 =A0gdImagePtr image =3D gdImageCreateFromPng( fp );
> =A0 =A0fclose( fp );
>
> =A0 =A0int x, y;
> =A0 =A0for( x=3D0; x < gdImageSX(image); ++x )
> =A0 =A0{
> =A0 =A0 =A0 =A0for( y=3D0; y < gdImageSY(image); ++y )
> =A0 =A0 =A0 =A0{
> =A0 =A0 =A0 =A0 =A0 =A0int color =3D gdImageGetPixel(image, x, y);
> =A0 =A0 =A0 =A0 =A0 =A0int alpha =3D gdImageAlpha(image,color);
> =A0 =A0 =A0 =A0 =A0 =A0if( alpha =3D=3D 0 || alpha =3D=3D gdTransparent )
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue;
> =A0 =A0 =A0 =A0 =A0 =A0printf( "PNG with 1bit alpha channel contains alph=
atransparent
> pixel\n" );
> =A0 =A0 =A0 =A0 =A0 =A0return 0;
> =A0 =A0 =A0 =A0}
> =A0 =A0}
> =A0 =A0return 0;
> }
>
>
>
>
> --
> GD Devel Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--=20
Pierre

@pierrejoye | http://blog.thepimp.net | http://www.libgd.org