linccce

Image resize

Oct 4th, 2014
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.40 KB | None | 0 0
  1. <?php
  2.  
  3. ///////////////////////////////////////////////////////
  4. // FlowerBoy paveiksleliu mazinimo varikliukas v.1.2 //
  5. ///////////////////////////////////////////////////////
  6.     $filename = realpath($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_GET['f']);
  7.  
  8.     if (isset ($_GET['p'])) {
  9.         $plotis = $_GET['p'];
  10.     }
  11.     if (isset ($_GET['a'])) {
  12.         $aukstis = $_GET['a'];
  13.     }
  14.     if (isset ($_GET['max'])) {
  15.         $dydis = getimagesize($filename);
  16.         if ($dydis['0'] <= $dydis['1']) {
  17.             $aukstis = $_GET['max'];
  18.         }
  19.         if ($dydis['0'] > $dydis['1']) {
  20.             $plotis = $_GET['max'];
  21.         }
  22.     }
  23.     if (isset ($_GET['min'])) {
  24.         $dydis = getimagesize($filename);
  25.         if ($dydis['0'] >= $dydis['1']) {
  26.             $aukstis = $_GET['min'];
  27.         }
  28.         if ($dydis['0'] < $dydis['1']) {
  29.             $plotis = $_GET['min'];
  30.         }
  31.     }
  32.  
  33.     header("Content-type: image/jpeg");
  34.     $source = imagecreatefromjpeg($filename);
  35.  
  36.     if ($plotis != "") {
  37.         $thumbX = $plotis;
  38.         $imageX = imagesx($source);
  39.         $imageY = imagesy($source);
  40.         $thumbY = (int)(($thumbX * $imageY) / $imageX);
  41.     }
  42.  
  43.     if ($aukstis != "") {
  44.         $thumbY = $aukstis;
  45.         $imageX = imagesx($source);
  46.         $imageY = imagesy($source);
  47.         $thumbX = (int)(($thumbY * $imageX) / $imageY);
  48.     }
  49.     $dest = imagecreatetruecolor($thumbX, $thumbY);
  50.  
  51.     imagecopyresampled($dest, $source, 0, 0, 0, 0, $thumbX, $thumbY, $imageX, $imageY);
  52.  
  53.     imagejpeg($dest, "", "100");
  54.  
  55.     imagedestroy($dest);
  56.     imagedestroy($source);
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment