Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine the size of an image without downloading it (in full)?

I'm looking to get the dimensions, width and height, of a remotely hosted JPG. I have seen how it is possible to do this by downloading the full image.

However, it would be ideal if I could do this by downloading only enough to just get this information.

Typical images are 200K in size and reading in just a few K might at the beginning might be enough for JPGs:

curl_setopt($ch, CURLOPT_RANGE, "0-4096");

For reference, I've followed these answers/comments but to no avail (though they might be on the right track):

  • Get image dimensions with Curl
  • Alternative to CURLOPT_RANGE to grab a specific section

Has anyone been able to put the pieces together (withor without ImageMagick)?

like image 416
donohoe Avatar asked Sep 17 '11 06:09

donohoe


People also ask

How do you determine the size of an image?

Digital Imaging Tutorial - Basic Terminology. FILE SIZE is calculated by multiplying the surface area of a document (height x width) to be scanned by the bit depth and the dpi2. Because image file size is represented in bytes, which are made up of 8 bits, divide this figure by 8.

How do I know the size of my digital image?

Check the resolution of your pictures before sending On a computer, right-click on the picture file, open “Properties”. Navigate to the “Details” tab and scroll down to the “Image” section. Here you will see the dimensions (in pixels), the width, and the height of the picture.

How can I tell the size of a JPG image?

Image Properties in Windows Explorer If you right-click an image file in Windows Explorer and select Properties, you obtain the image information with the pixel size. You can see how many pixels the image is made up of, and the image resolution.


1 Answers

How about using ImageMagick's ping functionality like this:

identify -ping -format "%wx%h" http://www.google.com/logos/giroux1.jpg
482x142
like image 78
Mark Setchell Avatar answered Oct 01 '22 11:10

Mark Setchell