Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. if(!empty($_GET['i'])){
  4.         if($img=realpath('../'.$_GET['i'])){
  5.                
  6.                 $name=basename($img);
  7.                 $ext=strtolower(substr($img,strrpos($img,'.')+1));
  8.                 $mime='image/'.str_replace('jpg','jpeg',str_replace('apng','png',$ext));
  9.  
  10.                 list($width_orig, $height_orig) = getimagesize($img);
  11.                 $width = empty($_GET['w']) ? $width_orig : $_GET['w'];
  12.                 $height = empty($_GET['h']) ? $height_orig : $_GET['h'];
  13.                
  14.                 $ratio = $width/$height;
  15.                 $ratio_orig = $width_orig/$height_orig;
  16.                
  17.                 // width, height:                               306  x 182              1,68
  18.                 // width_orig, height_orig:             2560 x 1600             1,6
  19.                
  20.                 if ($ratio < $ratio_orig) {
  21.                         $width_new = $height*$ratio_orig;
  22.                         $height_new = $height;
  23.                 } else {
  24.                         $width_new = $width;
  25.                         $height_new = $width/$ratio_orig;
  26.                 }
  27.  
  28.                 // Resample
  29.                 $image_p = imagecreatetruecolor($width, $height);
  30.                 $image = imagecreatefromjpeg($img);
  31.                 imagecopyresampled($image_p, $image, ($width-$width_new)/2, ($height-$height_new)/2, 0, 0, $width-($width-$width_new), $height-($height-$height_new), $width_orig, $height_orig);
  32.                
  33.                 // Output
  34.                 header('Content-Disposition: inline; filename="'.$name.'"');
  35.                 header('Content-Type: '.$mime);
  36.                 imagejpeg($image_p, null, 100);
  37.                
  38.                 die();
  39.         }
  40. }