Advertisement
xandr91

Q2APHP - remove GD library resizing

Apr 5th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1.     public function resizeimg($filename, $smallimage, $w, $h)
  2.     {    
  3.         $size_img = getimagesize($filename);
  4.         $w = $size_img[0];
  5.         $h = $size_img[1];
  6.         $ratio = $w/$h;  
  7.         if (($size_img[0]<$w) && ($size_img[1]<$h)) return true;
  8.         $src_ratio=$size_img[0]/$size_img[1];
  9.         if ($ratio<$src_ratio) $h = $w/$src_ratio;
  10.         else $w = $h*$src_ratio;
  11.         $dest_img = imagecreatetruecolor($w, $h);  
  12.         $white = imagecolorallocate($dest_img, 255, 255, 255);  
  13.         switch($size_img[2])  
  14.         {
  15.             case 1:
  16.             {
  17.                 $src_img = imagecreatefromgif($filename);
  18.                 imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);                
  19.                 imagegif($dest_img, $smallimage);
  20.             }
  21.             case 2:
  22.             {
  23.                 $src_img = imagecreatefromjpeg($filename);                      
  24.                 imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);                
  25.                 imagejpeg($dest_img, $smallimage);
  26.             }
  27.             case 3:
  28.             {
  29.                 $src_img = imagecreatefrompng($filename);
  30.                 imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $w, $h, $size_img[0], $size_img[1]);                
  31.                 imagepng($dest_img, $smallimage);
  32.             }
  33.         }    
  34.         imagedestroy($dest_img);
  35.         imagedestroy($src_img);
  36.         return true;          
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement