Get images sizes
Hi!
Can I get the width and height of an image before download it on a client side?
I have a serverless Web App sometimes even do not need an image itself but just fill the og:image:width
and og:image:height
and set a few parameter in the app.
-
Hi,
The Admin API can be used to query a particular resource and it will return the width and height of that resource: https://cloudinary.com/documentation/admin_api#details_of_a_single_resource
Note that the Admin API is rate limited, and more details can be found here based on your plan: https://cloudinary.com/documentation/admin_api#usage_limits
It might be beneficial to store the width and height with the public_id in case the Admin API limits are exceeded. The width and the height are returned in the upload response of a resource. Can you provide more details on why the image may not be needed?
Hope this helps!
-
Thank you for the answer.
Here is a good explanation of the reason https://stackoverflow.com/questions/50323461/image-dimensions-metadata-on-google-cloud-storage
Also, I use Photoswipe - http://photoswipe.com/documentation/getting-started.html for full image preview. To generate a gallery it requires the image sizes. This preview may be never opened by the particular user.
Also, placeholders for the images, do not use them in my project but it is definitely the reason.
In a PHP time that was simple, I try to build a serverless app now and the getting of all images from a folder and the sizes of images are surprisingly tough with a cloud or CDN. I've checked three of them.
To avoid login every user as an admin to Coudinary I see only the way is to keep sizes in a database
-
So, this is the solution that works for me finally https://github.com/image-size/image-size
Please sign in to leave a comment.
Comments
4 comments