
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 1.19 KB | hits: 15 | expires: Never
<?php
if(!empty($_GET['i'])){
if($img=realpath('../'.$_GET['i'])){
$name=basename($img);
$ext=strtolower(substr($img,strrpos($img,'.')+1));
$mime='image/'.str_replace('jpg','jpeg',str_replace('apng','png',$ext));
list($width_orig, $height_orig) = getimagesize($img);
$width = empty($_GET['w']) ? $width_orig : $_GET['w'];
$height = empty($_GET['h']) ? $height_orig : $_GET['h'];
$ratio = $width/$height;
$ratio_orig = $width_orig/$height_orig;
// width, height: 306 x 182 1,68
// width_orig, height_orig: 2560 x 1600 1,6
if ($ratio < $ratio_orig) {
$width_new = $height*$ratio_orig;
$height_new = $height;
} else {
$width_new = $width;
$height_new = $width/$ratio_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img);
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);
// Output
header('Content-Disposition: inline; filename="'.$name.'"');
header('Content-Type: '.$mime);
imagejpeg($image_p, null, 100);
die();
}
}