Jump to content

[SOLVED] Creating thumbnails


verycleanteeth

Recommended Posts

I've got the following code which is intended to create a thumbnail of an uploaded image. I'm getting an image of the the appropriate size, and it's saving it properly, but the images are nothing but black.

 

            if ($extension == 'gif')
                 $src_img = imagecreatefromgif("$image_path/$image_name");
            else     
                $src_img = imagecreatefromjpeg("$image_path/$image_name"); 
            
            if ($img_width > $thumb_width)
                $new_w = $thumb_width;
            else
                $new_w = $img_width;
               
            $image_name = str_replace('.gif', '.jpeg', $image_name);
                   
            $diff=$img_width/$new_w;
            $new_h=$new_w;
            
            if ($extension == 'gif')
                $dst_img = imagecreate($new_w,$new_h);          
            else    
                $dst_img = imagecreatetruecolor($new_w,$new_h);
                
            imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));

            if ($extension == 'gif')
                imagegif($dst_img, "$thumb_path/$image_name");      
            else
                imagejpeg($dst_img, "$thumb_path/$image_name");

 

 

This is my first time playing with the PHP image creation functions, so I'm sure I could be missing something very basic. Any help is appreciated! Thanks!

Link to comment
https://forums.phpfreaks.com/topic/132904-solved-creating-thumbnails/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.