<?php
$img = $_GET['im'];
$size = $_GET['size'];
$file = $img;
$ext = substr(strrchr($file, '.'), 1);
$w = $size;
$h = $size;
header('Content-type: image/jpeg');
list($w_o, $h_o) = getimagesize($file);
if ($size) {
if ($w && ($w_o < $h_o)) {
$w = ($h / $h_o) * $w_o;
} else {
$h = ($w / $w_o) * $h_o;
}
} else {
$w = $w_o;
$h = $h_o;
}
$image = imagecreatetruecolor($w, $h);
if ($ext == 'png') {
$img = imagecreatefrompng($file);
} else if ($ext == 'gif') {
$img = imagecreatefromgif($file);
} else {
$img = imagecreatefromjpeg($file);
}
imagecopyresampled($image, $img, 0, 0, 0, 0, $w, $h, $w_o, $h_o);
imagejpeg($image);
imagedestroy($img);
imageDestroy($image);
?>