Results 1 to 5 of 5

Thread: [RESOLVED] imagefill with gif

  1. #1

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Resolved [RESOLVED] imagefill with gif

    I have the below code using GD 2.0.34:

    The jpg setting works as expected, but for some reason the gif version isn't filling anything in when outputting but I can't work out why. Anyone got any thing to try as I'm completely out of ideas. Basically all the code should do would be to output the following squares to red.

    http://79.170.40.234/richant.co.uk/test.jpg
    http://79.170.40.234/richant.co.uk/test.gif

    PHP Code:

    <?php
    $type
    ="gif";

    $im imagecreatetruecolor(120,20);
    $red imagecolorallocate($im25500);

    if(
    $type=="jpg")
    {
        
    $image imagecreatefromjpeg('test.jpg');
        
    imagefill($image2945$red);

        
    header('Content-type: image/jpeg');
        
    imagejpeg($image);
    }
    elseif(
    $type=="gif")
    {
        
    $image imagecreatefromgif('test.gif');
        
    imagefill($image2945$red);

        
    header('Content-type: image/gif');
        
    imagegif($image);
    }
    imagedestroy($image);
    ?>

    Thanks in advance.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: imagefill with gif

    well, both of those images just display as a full black, small box. $red is a color assigned to the image $im, and you are creating another image for the jpg/gif called $image. just make sure $red is made for $image (within your if statements) and everything should be alright.

  3. #3

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Re: imagefill with gif

    My mistake. Those images linked to aren't actually hiding the code, but are the images being brought in, but thought it'd be useful incase I'd done something wrong with the images (incorrect amount of colours etc).

    The following links should show the difference with the code behind.

    http://79.170.40.234/richant.co.uk/imagefilljpg.php
    http://79.170.40.234/richant.co.uk/imagefillgif.php
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: imagefill with gif

    Try like this...

    Code:
    <?php
    $type="gif";
    
    if($type=="jpg")
    {
        $image = imagecreatefromjpeg('test.jpg');
        $red = imagecolorallocate($image, 255, 0, 0);
        imagefill($image, 29, 45, $red);
    
        header('Content-type: image/jpeg');
        imagejpeg($image);
    }
    elseif($type=="gif")
    {
        $image = imagecreatefromgif('test.gif');
        $red = imagecolorallocate($image, 255, 0, 0);
        imagefill($image, 29, 45, $red);
    
        header('Content-type: image/gif');
        imagegif($image);
    }
    imagedestroy($image);
    ?>
    Like kows said, in your original code, $red was being allocated for $im, not for $image. Why it then worked for jpg and not for gif, I don't know, but this should work for both.

  5. #5

    Thread Starter
    Hyperactive Member richy's Avatar
    Join Date
    Jan 1999
    Location
    Liverpool, England
    Posts
    353

    Re: imagefill with gif

    That works perfectly. Thanks very much to you both.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width