The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.
$img_file = "sourceimage.jpg";
header("Content-type: image/jpeg");
$width = 180;
list($width_orig, $height_orig) = getimagesize($img_file);
print("$width_orig, $height_orig
");
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, $img_file, 100);
imagedestroy($img_file);
Lifted mostly from PHP.net. Am I supposed to make this in a seperate file, then use it with HTML image tags? Had a look around the web, but couldn't find anything helpful. There's no apparent output, and my GD build is ok.
This has made my day though.
Really bloomin' useful, wish I'd sorted it out sooner! (by that I mean "wish I'd got Garin to sort it out sooner")
You, sire, are a genius.
EDIT: Yeah I did a quick test, uploaded a 0.5Mb file, thumbnailed it as a 27k file. Supoib.
> One more thing: I'm assuming that if I upload a large image, this
> technique is to dynamically create a thumbnail of small filesize? I
> know it's obvious, but just making sure it doesn't load the entire
> image first, then resize it...
Yes, the image resizing is being done on the server by PHP, which outputs a smaller image that the browser downloads.
If you're going to use this alot, you'd be advised to look at doing the resizing once and writing out file, rather than doing it on the fly everytime though.
$img_dir = "../images/products/image_";
$img_format = ".jpg";
$img_file = "$img_dir$img_id$img_format";
$width = 180;
header("Content-type: image/jpeg");
list($width_orig, $height_orig) = getimagesize($img_file);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, null, 100);
imagedestroy($image_p);
Super.
One more thing: I'm assuming that if I upload a large image, this technique is to dynamically create a thumbnail of small filesize? I know it's obvious, but just making sure it doesn't load the entire image first, then resize it...
EDIT: OK, this is what I have in the load_image.php file:
header("Content-type: image/jpeg");
$img_dir = "../images/products/image_";
$img_format = ".jpg";
$img_file = "$img_dir$img_id$img_format";
$width = 180;
list($width_orig, $height_orig) = getimagesize($img_file);
$height = (int) (($width / $width_orig) * $height_orig);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($image_p, 100);
imagedestroy($image_p);
?>
What HTML do I need to put in? ?
> So I won't be able to set the quality?
You can if you like. :)
imagejeg($image_p,100);
> should be....
>
> imagejeg($image_p);
So I won't be able to set the quality?