07 29th, 2008

If you created galleries once - you know how important create the small preview images. In PHP we easy can do it. Now we write small function which will change the size of image. If you need show the image preview do it:
<img ALT="preview" SRC="resize.php?url=image.jpg" />
Here file resize.php:

<?

function resize($img_src)
{
header('Content-type: image/jpeg'); list($width, $height) = getimagesize($img_src);

$source_img = imagecreatefromjpeg($img_src);

$dest_img = imagecreatetruecolor(64, 64);

imagecopyresampled($dest_img, $source_img, 0, 0, 0, 0, 64, 64, $width, $height);

imagejpeg($dest_img);
}

if(isset($_GET["url"]))
{
resize($_GET["url"]);
}
?>

Function simple and to explain as it works it is not needed. But if you need change size of many images
- it is needed to understand that this function will strongly slow work of site.