Forum Moderators: coopster
You are on the right track with the GD library; very powerful!
Try this. Use this for your image tag:
<img border="0" src="phalbumresize.php?userfile=somephoto.jpg">
somephoto.jpg being the name of the image you are getting out of the database.
This will be your phalbumresize.php file, or something like this. You will need to get the image from your database in your own code; I usually use images as files in a directory.
<?php
session_start();$thumbnailsize = 125; // or whatever you want
$userfile = $_REQUEST['userfile'];/*do something here to get the actual image so it is the var $userfile */
$size = GetImageSize ($userfile);
if($size[2] == '2'){
$src_img = imagecreatefromjpeg($userfile);
$headertype = "jpeg";
}elseif($size[2] == '3'){
$src_img = imagecreatefrompng($userfile);
$headertype = "png";
}if($size[0] > $size[1])
{
$new_w = $thumbnailsize;
$new_h = (int)($thumbnailsize * $size[1] / $size[0]);
}
else
{
$new_w = (int)($thumbnailsize * $size[0] / $size[1]);
$new_h = $thumbnailsize;
}$dst_img = imagecreatetruecolor($new_w,$new_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
header ("Content-type: image/$headertype");
if($size[2] == '2'){
imagejpeg($dst_img);
}elseif($size[2] == '3'){
imagepng($dst_img);
}
imagedestroy($dst_img);
?>
Tweak this a bit, but I'm pretty sure this is what you'll need. Let me know how you make out.
Jenny
But that might be too slow or too intensive if the images are big and you're displaying lots of thumbnails. Maybe you could add a new column to the database table (or a new table) and resize all of the images before-hand?