imagesetpixel() Troubles

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Taorluath
    New Member
    • Sep 2007
    • 9

    imagesetpixel() Troubles

    I'm trying to make a PHP script that increases the blue value of each pixel in an image by 1.
    It's important that the script goes pixel by pixel.
    For some reason, however, it outputs an image that is one solid color; a brownish red block.
    Why isn't this script only slightly increasing the values?? ??? ???



    Code:
    <?php
    $img = imagecreatefromgif('logo.gif');
    
    // get height and width
    $h=imagesy($img);
    $w=imagesx($img);
    
    //display image
    echo "<img src='out.gif' />";
    
    //cycle through every pixel and add 1 to the blue value of the pixel's rgb value
    $y=1;
    while($y < $h) {
    $x=1;
    while($x < $w) {
    
    $rgb = imagecolorat($img, $x, $y);
    $red = ($rgb >> 16) & 0xFF;
    $green = ($rgb >> 8) & 0xFF;
    $blue = $rgb & 0xFF;
    $blue++;
    
    //define the new color and assign it to the pixel
    //this is where things go wrong
    $color = imagecolorallocate($img, $red, $green, $blue);
    imagesetpixel($img, $x, $y, $color);
    $x++;
    }
    $y++;
    }
    
    echo imagegif($img, 'out.gif');
    ?>
    I know the problem is in these two lines by the way.
    Code:
    $color = imagecolorallocate($img, $red, $green, $blue);
    imagesetpixel($img, $x, $y, $color);
  • MarkoKlacar
    Recognized Expert Contributor
    • Aug 2007
    • 296

    #2
    Hi,

    Not quite sure what you're doint on line 9., you're displaying the image before anything has been done to it.

    Is there a way for you to post the original picture and the result picture?

    Thanks

    Comment

    Working...