Forum Moderators: coopster

Message Too Old, No Replies

Fastest way to get local image dimensions

         

csdude55

5:24 pm on Sep 27, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'm working with images already uploaded to my server, not remote.

I'm reading that getimagesize() is very slow, but I'm not sure if that only applies to remote images:

[php.net...]

Any suggestions on the fastest option to get the image dimensions when the image is stored locally?

I currently use:

if (is_readable($path_to . $img)) {
list($width, $height) = @getimagesize($path_to . $img);
// do stuff
}


The majority of the time, the image would be readable. If it's not then it means that there was a glitch in the server somewhere during the user's upload. Should I even test that it's readable first? Or am I wasting resources trying to prevent that 0.00001%?

Considered alternative:

if (list($width, $height) = @getimagesize($path_to . $img)) {
// do stuff
}