GD GIF

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

GD GIF

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

From The Manual on imagecreatetruecolor():

Note: This function will not work with GIF file formats.
Could that be the problem?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Just out of interest, what's in $gd2? You global it but then don't use it.
Post Reply