By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,946 Members | 741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,946 IT Pros & Developers. It's quick & easy.

Image Compression Problem

AMT India
P: 64
I have an image resizing function using GD Library in php.After resizing the gif images,they lose their animation properties.
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3.                 $file_name_src =  $upload_file;
  4.             $file_desination2 = $compressedPath;
  5.  
  6.               list($width_orig, $height_orig, $type) = getimagesize($file_name_src);
  7.  
  8.  
  9.                 if($type == "1" )
  10.                 {
  11.                     $image = imagecreatefromgif($file_name_src);
  12.  
  13.                 }
  14.                 elseif ($type=="2")
  15.                 {
  16.                     $image = imagecreatefromjpeg($file_name_src);
  17.                 }
  18.                 elseif($type=="3")
  19.                 {
  20.                     $image = imagecreatefrompng($file_name_src);
  21.                 }
  22.                 //echo $image."<br/>";
  23.                 $new_width = $new_width;
  24.                 $new_height = $new_height;
  25.  
  26.                     if ($new_width && ($width_orig < $height_orig)) 
  27.                     {
  28.                         $new_width = ($new_height / $height_orig) * $width_orig;
  29.                     } 
  30.                     else 
  31.                     {
  32.  
  33.                         $new_height = ($new_width / $width_orig) * $height_orig;
  34.                     }
  35.  
  36.  
  37.  
  38.  
  39.  
  40.                 // Resample
  41.                 $image_p = imagecreatetruecolor($new_width, $new_height);
  42.  
  43.                 //echo $image_p."<br/>";
  44.                 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
  45.  
  46.                 //echo $file_desination2;
  47.  
  48.  
  49.  
  50.                     if (function_exists("imagegif"))
  51.                     {        
  52.                         //header("Content-type: image/gif");
  53.                         imagegif($image_p,$file_desination2);
  54.                     }
  55.                     elseif (function_exists("imagejpeg"))
  56.                     {
  57.                         imagejpeg($image_p, $file_desination2, 100);
  58.                     } 
  59.                     elseif (function_exists("imagepng"))
  60.                     {
  61.                         imagepng($image_p,$file_desination2);
  62.                     }
  63.                     elseif (function_exists("imagewbmp")) 
  64.                     {
  65.                         imagewbmp($image_p,$file_desination2);
  66.                     } 
  67.                     else 
  68.                     {
  69.                         die("No image support in this PHP server");
  70.  
  71.                     }
  72.                      imagedestroy($image_p);
  73.                      chmod($file_desination2,0655);
  74.  
  75.                     return true;
  76.  
Regards,
AMTIndia
Jan 9 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.