function resize_image($filename)
{
$path = basename($filename); // trim off leading /../foo/stuff
$path = './path/to/'.$path; // and put ours on.
$src_img = imagecreatefromjpeg($path);
$srcsize = getimagesize($path);
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
header("content-type: image/jpeg");
imagejpeg($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);
}
Still doesn't check that the file actually exists, of course.
Arty Ziff wrote:I'd like to avoid resizing the image and dumping it in a temp directory. That could get huge.
If you mean generating the thumbnails once and storing them in a directory, and serving those: that is better than regenerating them every time you want to serve them. Less processing power, less memory consumption, less time. More disk space, sure, but not that much more. (For one project, at one point I had 65,000 JPEGs (624x352 pixels stored with a high quality setting); all told they occupied just over 1.2GB. I could put that on my phone and still have enough space left over for a web site, its database, and the software to serve it all. It's trivial for a modern PC or server box.)