curl -s -v -X HEAD http://sitename.com/123.jpg 2>&1 | grep '^< Last-Modified:' gets me a date. Any way I can retrieve gps coordinates of an image? Any other metadata?

  • 3
    This is not a curl question but a jpeg-parsing one. – JohnW Oct 2 '16 at 12:47

What you are getting there is not the time at which the photo was taken. It is the time at which the 123.jpg file was last modified (or created/uploaded onto the server). That information comes from the web server, which gets it from the file's timestamps. The photo could very well be 10 years older than what you get. Actually, it wouldn't be too difficult to make it look like it comes from the future!

The information you're looking for is (optionally) stored into the image's metadata. From a webserver's perspective, that's part of the file's actual content, which means an HTTP HEAD request will not be enough. First, you need to download the file. Let's use that picture of a boat as an example.

If you run your curl command, you'll see that the file was last modified on the 13th of October 2015. Once you've downloaded the file, this date will also appear in the file's timestamps (provided you preserve them accross downloads, which I believe wget does).

Now once you've got the file, all you need to do is access its metadata. On Linux, I'd say identify and exiftool are the most popular choices for that. In your case:

$ identify -format "%[EXIF:*GPS*]" image.jpg
$ exiftool -gpslatitude -gpslongitude image.jpg

Note that you don't really have to download the contents into an actual file in order to run these checks. You could easily use a pipe:

$ curl http://example.com/image.jpg | identify -format "%[EXIF:*GPS*]" -
$ curl http://example.com/image.jpg | exiftool -gpslatitude -gpslongitude -

An important note though: geotagging is not a systematic process. Not all images have GPS coordinates embedded in them. If the device used to take the picture is GPS-enabled and actually writes GPS metadata, then you're good (smartphones can do that...). Otherwise, these two commands will not return anything, in which case you'll have to be more creative to determine the location...

  • Running exiftool directly on the jpg ... file is more efficient – GAD3R Oct 2 '16 at 14:35
  • 2
    "in which case you'll have to be more creative to determine the location..." - post it to travel.SE and say you want to visit the location in the picture – Random832 Oct 2 '16 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.