Advertisement
cornedor

Untitled

Nov 28th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. <?php
  2.     // Get image
  3.     $handle = fopen($_GET['url'], 'rb');
  4.     $img = new Imagick();
  5.     $img->readImageFile($handle);
  6.  
  7.     $orgWidth = $_GET['width'];
  8.     $orgHeight = $_GET['height'];
  9.  
  10.     // Do math
  11.     $width = $orgWidth;
  12.     $height = $orgHeight;
  13.     $wah = $width > $height;
  14.     $r;
  15.     if(!$wah)
  16.     {
  17.         $r = $img->width/$img->height;
  18.         $width = $height*$r;
  19.     }
  20.     else
  21.     {
  22.         $r = $img->height/$img->width;
  23.         $height = $width*$r;
  24.     }
  25.  
  26.     // Resize iamge
  27.     $img->resizeImage($width, $height, 0, 0);
  28.  
  29.     // Crop image
  30.     $offsetX = ($img->width - $orgWidth)/2;
  31.     $offsetY = ($img->height - $orgHeight)/2;
  32.     $img->cropImage($orgWidth, $orgHeight, $offsetX, $offsetY);
  33.  
  34.     echo '<img src="data:image/jpg;base64,'.base64_encode($img->getImageBlob()).'" alt="" />';
  35.     // $img->writeImage('images/foo.jpg'); om op te slaan
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement