Advertisement
Speeedfire

Untitled

Dec 26th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. function img_resize( $tmpname, $size, $save_dir, $save_name, $maxisheight = 0 )
  2.     {
  3.     $save_dir     .= ( substr($save_dir,-1) != "/") ? "/" : "";
  4.     $gis        = getimagesize($tmpname);
  5.     $type        = $gis[2];
  6.     switch($type)
  7.         {
  8.         case "1": $imorig = imagecreatefromgif($tmpname); break;
  9.         case "2": $imorig = imagecreatefromjpeg($tmpname);break;
  10.         case "3": $imorig = imagecreatefrompng($tmpname); break;
  11.         default:  $imorig = imagecreatefromjpeg($tmpname);
  12.         }
  13.  
  14.         $x = imagesx($imorig);
  15.         $y = imagesy($imorig);
  16.        
  17.         $woh = (!$maxisheight)? $gis[0] : $gis[1] ;    
  18.        
  19.         if($woh <= $size)
  20.         {
  21.         $aw = $x;
  22.         $ah = $y;
  23.         }
  24.             else
  25.         {
  26.             if(!$maxisheight){
  27.                 $aw = $size;
  28.                 $ah = $size * $y / $x;
  29.             } else {
  30.                 $aw = $size * $x / $y;
  31.                 $ah = $size;
  32.             }
  33.         }  
  34.         $im = imagecreatetruecolor($aw,$ah);
  35.     if (imagecopyresampled($im,$imorig , 0,0,0,0,$aw,$ah,$x,$y))
  36.         if (imagejpeg($im, $save_dir.$save_name))
  37.             return true;
  38.             else
  39.             return false;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement