<?php header("Content-type: image/jpeg"); define('MAX_THUMB_HEIGHT', $_GET['h']); define('MAX_THUMB_WIDTH', $_GET['w']); $sourceFileName = $_GET['img']; $imgs = imagecreatefromjpeg($_GET[img]); // Get new dimensions $width = @imagesx($imgs); $height = @imagesy($imgs); //list($width, $height) = getimagesize($sourceFileName); $ratio = $width/$height; if ($ratio < 1) { // height is bigger $newHeight = MAX_THUMB_HEIGHT; $newWidth = round($newHeight*$ratio); } else { // width is bigger $newWidth = MAX_THUMB_WIDTH; $newHeight = round($newWidth/$ratio); } // create thumb and resample $image_p = imagecreatetruecolor($newWidth, $newHeight); $image = imagecreatefromjpeg($sourceFileName); imagecopyresized($image_p, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); // save thumb imagejpeg($image_p, "", 100); ?>