Error in Converting GIF Image to Black & White

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • retheeshnewage@gmail.com

    #1

    Error in Converting GIF Image to Black & White

    I have a doubt in php.I wrote a php program to convert colour Images to

    balck & white.It is working fine with JPEG files and PNG files.When it
    comes to GIF files I am not getting the colour Image.I think I found
    the reason of getting error.But I am not able to solve it
    I am pasting the code which I wrote

    The reason I think is when I am extracting the RGB value from the
    image,R and G will be zero everytime.But I am getting the value of B.
    As a Result I am getting a Black Box instead of Black and white Image


    $file = 'logo2.gif';
    header('Content-type: image/gif');
    $imgtype = "gif";
    list($width, $height) = getimagesize($f ile);
    $source = imagecreatefrom gif($file);
    $bwimage= imagecreate($wi dth, $height);


    for ($c=0;$c<256;$c ++)
    {
    $palette[$c] = imagecoloralloc ate($bwimage,$c ,$c,$c);



    }


    function yiq($r,$g,$b)
    {
    return (($r*0.299)+($g *0.587)+($b*0.1 14));


    }


    for ($y=0;$y<$heigh t;$y++)
    {
    for ($x=0;$x<$width ;$x++)
    {
    $rgb = imagecolorat($s ource,$x,$y);
    $r = ($rgb >16) & 0xFF;//error is here I am getting a value of zero
    for $r and $g
    $g = ($rgb >8) & 0xFF;//error getting the value zero everytime
    $b = $rgb & 0xFF;//Here I am getting value

    $gs = yiq($r,$g,$b);
    imagesetpixel($ bwimage,$x,$y,$ palette[$gs]);



    }
    }


    imagegif($bwima ge);

  • Kimmo Laine

    #2
    Re: Error in Converting GIF Image to Black &amp; White

    <retheeshnewage @gmail.comwrote in message
    news:1154322970 .581306.230480@ b28g2000cwb.goo glegroups.com.. .
    >I have a doubt in php.I wrote a php program to convert colour Images to
    >
    balck & white.It is working fine with JPEG files and PNG files.When it
    comes to GIF files I am not getting the colour Image.I think I found
    the reason of getting error.But I am not able to solve it
    I am pasting the code which I wrote
    >
    The reason I think is when I am extracting the RGB value from the
    image,R and G will be zero everytime.But I am getting the value of B.
    As a Result I am getting a Black Box instead of Black and white Image
    >

    In the manual at php.net it says:
    Note: GIF support was removed from the GD library in Version 1.6, and added
    back in Version 2.0.28. This function is not available between these
    versions.

    Check your GD version to see if it supports gif or not.

    (I remember a time when gif was not supported. It's nice to see they've
    added it in the package again.)

    --
    "Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
    http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
    spam@outolempi. net || Gedoon-S @ IRCnet || rot13(xvzzb@bhg byrzcv.arg)


    Comment

    Working...