One way to improve page loading is to specify image dimesions (hieght width). In PHP this can be done with getimagesize(), however I can imagine this would be quite slow to execute if you have alot of images.
What is the best way to dynamically get image dimensions of many images with minimal effect on page loading. We are talking about 50+ images.
How to get the dimensions of image with React? To get the dimensions of image with React, we can get it from the load event handler of the image.
You can easily get the original size (width and height) of the image using JavaScript. Assume that you have an image which is originally 250px wide and you make it 550px wide by CSS style or HTML “width” property.
Assume that you have an image which is originally 250px wide and you make it 550px wide by CSS style or HTML “width” property. The naturalWidth will return the original width 250 although the display width is 550. Assume that you have an image which is originally 100px high and you make it 250px high by CSS style or HTML “height” property.
naturalHeight Assume that you have an image which is originally 100px high and you make it 250px high by CSS style or HTML “height” property. The naturalHeight will return the original height 100 although the display height is 250.
I've just tested with 55 pcs of 5+ MB images:
Imagemagick's getImageGeometry took 5.3 seconds
(because after each file you have to recreate the imagick object), while getimagesize went thru the images in 0.032 seconds
. The latter is more than acceptable.
If not, store the dimensions in the database.
EDIT: Also, if you get the files through TCPIP, that slows down the process considerably. So, if you call it this way:
getimagesize('http://www.blabla.com/pic.jpg');
Instead of
getimagesize('localdir/hereiam/pic.jpg');
you get some network overhead.
Plus, if those pictures consistently have EXIF data (made with a digital camera), then you can use the PHP exif_ functions, like: exif_read_data.
Question: which PHP version you are using? Older 4.x versions had smaller problems regarding getimagesize on certain filesystems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With