Page 1 of 1

GD GIF

Posted: Mon Nov 21, 2005 9:42 am
by s.dot
im trying to create a thumb of a GIF image. currently this function produces a blank, black image

Code: Select all

function createthumb($name,$filename,$new_w,$new_h){
    global $gd2;
    $system=explode(".",$name);
    $src_img=imagecreatefromgif($name);
    $old_x=imageSX($src_img);
    $old_y=imageSY($src_img);
    if ($old_x > $old_y) {
        $thumb_w=$new_w;
        $thumb_h=$old_y*($new_h/$old_x);
    }
    if ($old_x < $old_y) {
        $thumb_w=$old_x*($new_w/$old_y);
        $thumb_h=$new_h;
    }
    if ($old_x == $old_y) {
        $thumb_w=$new_w;
        $thumb_h=$new_h;
    }
    $dst_img=imagecreatetruecolor($thumb_w,$thumb_h);
    imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
    imagegif($dst_img,$filename);
    imagedestroy($dst_img);
    imagedestroy($src_img);
i called the function with this

Code: Select all

createthumb($dir.$_FILES['filetoupload']['name'],$dir."thumbs/".$_FILES['filetoupload']['name'],100,100);
the file that is being uploaded is a gif, so there was no need for checks to make sure its gif

Posted: Mon Nov 21, 2005 9:56 am
by Maugrim_The_Reaper
Not tracking GD all that recently, but is your current PHP version supporting GIFs? There was a license issue which saw PHP only carrying read-only support way back (wasn't resolved last I checked - a while ago now).

Probably not, but just a thought.

Posted: Mon Nov 21, 2005 9:57 am
by Buddha443556
From The Manual on imagecreatetruecolor():

Note: This function will not work with GIF file formats.
Could that be the problem?

Posted: Mon Nov 21, 2005 10:03 am
by s.dot
that could be a problem.

however, i changed the transparency of the image to white instead of transparent, and the file was thumbnailed properly

... seems odd now that you show me that imagecreatetruecolor() excerpt

Posted: Mon Nov 21, 2005 10:05 am
by Maugrim_The_Reaper
I think its a candidate, though checking again there is now write GIF support from 4.3.9. (not a clue how that impacts the other image functions). Seems likely... Does the code above work with other formats, e.g. PNG/JPG?

Posted: Mon Nov 21, 2005 10:08 am
by s.dot
yes it works great with JPG/PNG, of course i have those inside of a switch to use different functions (ie imagecreatefromjpeg instead of imagecreatefromgif)

Posted: Mon Nov 21, 2005 10:15 am
by onion2k
Just out of interest, what's in $gd2? You global it but then don't use it.