Jump to content

Reason for Slow loading images?


galvin

Recommended Posts

I have this code below in a while loop, that gets looped through about 10 times and is simply resizing a slightly larger image to fit within a 50px max square. There is other code on my page, but I've narrowed the slowness down to this specific bit of code (i.e. if I take this snippet out, the page loads instantly).  With this snippet, the page takes between 5 and 10 seconds to load, which seems absurd for 10 images.  FYI, the original images are no larger than 200 px on either side, so it's not like it's looping through large image files. 

 

Anyone know why this might be taking so long?  Should I be doing it differently somehow?

 

		
list($width,$height) = getimagesize($myimage);
if ($width > $height) {
$datasofar .= "width=50 /></span>";
} elseif ($height > $width) {
$datasofar .= "height=50 /></span>";
} else { //height and width must be equal so just set width = 50, but could just as easily set height to 50
$datasofar .= "width=50 /></span>";
}

Link to comment
Share on other sites

I would think it is php working out the size of the image on the following line

 

list($width,$height) = getimagesize($myimage);

 

you could try setting the $width and $height to a constant here to see if it is indeed slowing down your script

 

Not sure this really helps because I'm not sure of any other way of getting the size of the image dynamically.

Link to comment
Share on other sites

I commented out that line and added...

$width=90;
$height=110;

 

It ran a little quicker (like 3 full seconds instead of 5+, which still seems long to me, but maybe I don't know what I'm talking about and this amount of time is perfectly normal :)

 

Not sure if it matters, but the images that are being checked are NOT on my server, they are image files on my Amazon S3 account, so they are external image URLs.  Maybe it takes significantly longer to check external image URLs???

Link to comment
Share on other sites

Damn, I was afraid that was answer (i.e. that's just the way those functions are, they take longer).  Thanks for the tip though, I'll see if I can only have them load once.

 

And I guess this would be a good time to look at adding some sort of spinning "working" gif so the user knows something is happening, rather than them wondering what's taking so long and recklessly clicking the link over and over :)

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.