Possible Duplicate:
Thumbnails in php generated gallery loading slow
Code link can be found on the bottom of the page.
The site is running from 1and1.co.uk linux based system, good enough to load the gallery much faster than it currently does.
The php generated thumbnails are loading a bit slow, can you tell me why?
http://site-perf.com/cgi-bin/show.cgi?id=vz5le19Fp5E
code:
http://satinaweb.com/tmp/functions.txt
Here is crop.php:
$sourceimage = $_GET['a'];
function crop($sourceimage) {
// Draw & resize
header('Content-Type: $imsz[\'mime\']');
list($width, $height) = getimagesize($sourceimage);
if($width > $height){
$new_width = 100;
$new_height = 75;
} else {
$new_width = 75;
$new_height = 100;
}
$image = imagecreatefromjpeg($sourceimage);
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagejpeg($image_p);
imagedestroy($image_p);
imagedestroy($image);
}
crop($sourceimage);
If you have questions, please ask!
What you should have noticed from your site-perf graph most is that,
I’m not going to look through all your code, but you have a file called
crop.php. This is going to be slow because it (presumably) crops the images on every page load, which takes a relatively long time (made apparent from the site-perf data); for each request, the browser spends most of it’s time waiting for the server to respond.You should consider using a cache folder to store cropped images and serve them up as-is to reduce loading time.
In
crop.php, you could do something like this (pseudo code):Every time you call
crop(), you read the image, modify it and spit it out to the client. This is incredibly wasteful, because you need to re-process the image for every request. You’re even destroying the image afterwards (not that this makes much difference). Instead, useis_file()with a cache directory, and save the image to disk as well as sending it to the client.Now, your script might look like this:
This is untested, but should work. Please don’t just copy and paste the above code; read through it and make sure you understand how and why it does what it does.