<?php
# $Id: resize.php 686 2006-11-28 18:49:08Z bb $
# returns a resized image
#
# @param image string
# The image to resize (relative to ~/public_html)
# @param width integer
# The width of the resized image. Smaller images are not enlarged.
$image = $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['image'];
if (preg_match('/jpe?g$/', $image))
$im = imagecreatefromjpeg($image);
else if (preg_match('/png$/', $image))
$im = imagecreatefrompng($image);
else if (preg_match('/gif$/', $image))
$im = imagecreatefromgif($image);
if (!$im)
return;
$width = isset($_GET['width']) ? $_GET['width'] : 600;
if (imagesx($im) > $width) {
// Create a image with the new dimensions
$height = imagesy($im) * $width / imagesx($im);
$new = imagecreatetruecolor($width, $height);
// Resize the image
imagecopyresampled($new, $im, 0, 0, 0, 0,
$width, $height, imagesx($im), imagesy($im)
);
imagedestroy($im);
$im = $new;
}
// Return the image
header("Content-Type: image/jpeg");
imageinterlace($im, 1);
imagejpeg($im);
imagedestroy($im);
?>