Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.