Код => Функция

freshbg1

Registered
Може ли да ми преработите този код на функция, която да посочва WIDTH и HEIGHT. Моля тествайте преди да поствате! +1

Код:
                $imagepath = $filename;
               $save = "../uploads/images/th_" . $imagepath; //This is the new file you saving
               $file = "../uploads/images/" . $imagepath; //This is the original file
              $x = @getimagesize($file);
  switch($x[2]) {
   case 1:
        $image = imagecreatefromgif($file);
       break;
   case 2:
        $image = imagecreatefromjpeg($file);
       break;
   case 3:
        $image = imagecreatefrompng($file); 
       break;
   default:
        echo "file is not a valid image file.<br>";
        $stop = '1';
       break;
  }
         if($stop != 1) {
              list($width, $height) = getimagesize($file) ;
 
              $modwidth = $width;
 
              $diff = $width / $modwidth;
 
              $modheight = $height / $diff;
              $tn = imagecreatetruecolor($modwidth, $modheight) ;
             
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
 
              imagejpeg($tn, $save, 100) ;
 
              $save = "../uploads/images/th_" . $imagepath; //This is the new file you saving
              $file = "../uploads/images/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ;
 
              $modwidth = 120;
 
              $diff = $width / $modwidth;
 
              $modheight = 90;
              $tn = imagecreatetruecolor($modwidth, $modheight) ;
       $x = @getimagesize($file);
  switch($x[2]) {
   case 1:
        $image = imagecreatefromgif($file);
       break;
   case 2:
        $image = imagecreatefromjpeg($file);
       break;
   case 3:
        $image = imagecreatefrompng($file); 
       break;
   default:
        echo "file is not a valid image file.";
   }
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
 
              imagejpeg($tn, $save, 100) ; 
          }
:?: :?: :?:
 

Back
Горе