I would like the height*width of a remote image. Could that be done with Curl, and if so how?
Curl can not do that. Quoting from http://curl.haxx.se/
Blockquote curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos...), file transfer resume, proxy tunneling and a busload of other useful tricks.
Curl can be used to look at the http headers and guessing the image type, but to determine the dimension of the image you will need the image itself.
You can use eg. the Python Imaging Library to actually checking the dimension when the image has been downloaded though.
getimagesize() is the function you want.
It should be able to download a remote image and analyze it.
Edit: As a more direct answer to your question, Curl cannot analyze an image directly, but it can certainly fetch it for you, in which case you can then use the GD library to analyze it. getimagesize() manages to do the fetching as well though, so you can leave Curl out of the equation.
The height and width of an image are attributes inside the image file and you need to retieve the file to be able to access them. Depending on the image format, this attributes will be in diferent places of the image metadata. You can do this with getimagesize, but bear in mind that you are actually retrieving the full image, which will affect the performance of your operation.
In the event of a large image, you can try something like start fecthing the image to your server and, as soon as you start receiving data and know the format of the image, wait until you receive enough from the image to look at the height and width information and stop the transfer. You will most likely need to do this job yourself, as image libraries and built in functions in APIs will probably expect a full image to work properly.
If by chance you control the server where the images are, you are better of writting a small script hosted in that server that given an image file identifier returns the height and width for that image.
Per the CURL docs:
With HTTP 1.1 byte-ranges were introduced. Using this, a client can request to get only one or more subparts of a specified document. Curl supports this with the -r flag.
Get the first 100 bytes of a document: curl -r 0-99 http://www.get.this/ Get the last 500 bytes of a document: curl -r -500 http://www.get.this/
Given that you can request just parts of the image via CURL, you might very well be able to accomplish what you are looking to do. Now the key is being able to pass the partial image to something like GD (or your application of choice) to extract and report the image dimensions.
If you are only working with JPEGs your life gets easier as the dimensions are stored in the beginning of the file in the header with specified markers. See another discussion here at stackoverflow entitled, "Getting Image size of JPEG from its binary".
Though it needs some more work, it would seem something like this would be getting you to the correct marker:
curl -r 0-999 --url http://www.google.com/logos/giroux1.jpg | grep -n $'\xc0'
Some other reference sources that I came across when googling for JPEG info:
Read JPEG dimensions in C++ without reading the whole file
Read JPEG dimensions in C# without reading the whole file
Read JPEG dimensions in Java without reading the whole file
JPEG Header Info
http://web.archive.org/web/20080224153210/http://www.obrador.com/essentialjpeg/headerinfo.htm
Hopefully this separate post is warranted as I was concerned that this answer would be lost as simply a comment on my previous post. And why do think this deserving of a separate post, you ask? Well, I think I have found an answer.
Granted I am using the CLI version rather than libcurl (in your language of choice) but I futzed around enough until I got a working answer. It is as follows:
curl -r 0-25 --silent http://www.google.com/logos/giroux1.jpg | identify -format "%wx%h" -
What is happening here in the above example is CURL is using the -r flag to request only the first 25 bytes of the file and piping that to the imagemagick command called IDENTIFY where it extracts the dimensions and prints them out in the specified format.
For more about the info that you can extract with IDENTIFY visit http://www.imagemagick.org/script/identify.php
To make the command a bit more script friendly I would add "2> /dev/null" to the end to suppress error messages (stderr):
curl -r 0-25 --silent http://www.google.com/logos/giroux1.jpg | identify -quiet -format "%wx%h" - 2> /dev/null
Unlike GIF images where the dimensions appear to be tightly tied to the first 10-20 bytes, there does not appear to be a fixed quantity of bytes required to get to the dimensions data from a JPEG. Some more testing has revealed that for large images you might need to request up to the first ~10k to get to the dimensions data. A good example is the following 4MB image from NASA: http://veimages.gsfc.nasa.gov/17921/southern_africa_25jul02_lrg.jpg I found that no less than 5971 bytes will render the dimensions (10836 x 9324) but I guess that is better than having to download the whole thing.
Point being...your mileage may vary, so try it out yourself.