<?php
// make thmubnail of image
function sizeImage($image, $x, $y, $proportional) {
if (!$attr = getimagesize($image)) {
trigger_error("GD: Image does not exist. Must be gif, jpeg, or png!",E_USER_ERROR);
}
switch ($attr[2]) {
case 1:
$image = imagecreatefromgif($image);
break;
case 2:
$image = imagecreatefromjpeg($image);
break;
case 3:
$image = imagecreatefrompng($image);
break;
default:
trigger_error("GD: Image type wrong. Must be gif, jpeg, or png!", E_USER_ERROR);
}
if ($proportional) {
if ($attr[0]<$attr[1]){
$x = $y * ($attr[0]/$attr[1]);
}
else{
$y = $x / ($attr[0]/$attr[1]);
}
}
$newimage = imagecreatetruecolor($x,$y);
imagecopyresampled($newimage, $image, 0, 0, 0, 0, $x, $y, $attr[0], $attr[1]);
imagepng($newimage);
imagedestroy($image);
imagedestroy($newimage);
}
$image = $_GET['image']; //image location
$x = 115; //width
$y = 90; //height
$proportional = TRUE; //proportional or not
header("Content-type: image/png"); //so we can use the image right in a tag. <img src="image.php?image=me.gif">
sizeImage($image, $x, $y, $proportional);
?>
link to images in IMG SRC tag as ..<img src="image.php?image=me.gif">
this take image and convert to smaller size keeping ratio when resizing. you may change W and H to needs.