Advertisement
xandr91

webwall-png

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