Is there a package to read EXIF data from a jpg image?

I’m looking for a package to read EXIF data from a jpg image. I had hoped that ImageMetadata would do that, but but when I load a jpg image, all the metadata is gone, e.g.,
img=load(“/Users/prange/Downloads/TKNE8480.JPG”)
3024×4032 Array{RGBX{N0f8},2} with eltype RGBX{Normed{UInt8,8}}
What is the preferred way to extract this information? In particular, I’m trying to extract the GPS coordinates.

ImageMagick.jl has some undocumented functions getimageproperty and getimageproperties. Let us know if those help.

ImageMagick contains a function magickinfo() that reads the EXIF info from an image file without loading the image. This is fast and provides just what I need. Thanks.

1 Like

@michael-prange I’m trying to extract some information from JPG, especially date and time the picture was taken, for that I’m using the ImageMagick.magickinfo() function as follow:

dir = "/Users/yohan/Documents/julia-programming/sbs_dist.jl/pic"
info = ImageMagick.magickinfo(joinpath(dir,"CT020072.JPG"))
show(info)

and here is the output:

["date:create", "date:modify", "exif:ApertureValue", "exif:ColorSpace", "exif:ComponentsConfiguration", "exif:CustomRendered", "exif:DateTime", "exif:DateTimeDigitized", "exif:DateTimeOriginal", "exif:ExifImageLength", "exif:ExifImageWidth", "exif:ExifOffset", "exif:ExifVersion", "exif:ExposureBiasValue", "exif:ExposureMode", "exif:ExposureProgram", "exif:ExposureTime", "exif:FileSource", "exif:FlashPixVersion", "exif:FNumber", "exif:FocalLength", "exif:GainControl", "exif:ImageDescription", "exif:InteroperabilityOffset", "exif:ISOSpeedRatings", "exif:LightSource", "exif:Make", "exif:MakerNote", "exif:MaxApertureValue", "exif:MeteringMode", "exif:Model", "exif:Orientation", "exif:ResolutionUnit", "exif:SceneCaptureType", "exif:ShutterSpeedValue", "exif:Software", "exif:thumbnail:Compression", "exif:thumbnail:InteroperabilityIndex", "exif:thumbnail:InteroperabilityVersion", "exif:thumbnail:JPEGInterchangeFormat", "exif:thumbnail:JPEGInterchangeFormatLength", "exif:thumbnail:ResolutionUnit", "exif:thumbnail:XResolution", "exif:thumbnail:YResolution", "exif:WhiteBalance", "exif:XResolution", "exif:YCbCrPositioning", "exif:YResolution", "jpeg:colorspace", "jpeg:sampling-factor", "unknown"]

As there are not documentation about this function, I would like to know how I can extract the date and time from the data of the JPG picture. Here in the results are only given strings but not really the information I need. Thanks in advance for the time you will take to help me.

Yohan,

Here is how I extracted some image information. I hope this helps. Note that the coordinates are given as ratios for degrees, minutes and seconds. You just need to do the division yourself.

Michael

magickinfo(“IMG_6477.jpeg”,
(“exif:GPSLatitude”,“exif:GPSLatitudeRef”,
“exif:GPSLongitude”,“exif:GPSLongitudeRef”,
“exif:GPSAltitude”))

Dict{String,Any} with 5 entries:
  "exif:GPSLongitudeRef" => "W"
  "exif:GPSLatitude"     => "44/1, 22/1, 2326/100"
  "exif:GPSLatitudeRef"  => "N"
  "exif:GPSLongitude"    => "71/1, 13/1, 5301/100"
  "exif:GPSAltitude"     => "261189/757"
3 Likes

@michael-prange, Thank you very much it’s working, what was missing only is to specify in the function the information I wanted to extract (a beginner’s mistake). I didn’t understood that the strings I had was actually the list of all information I can extract and in which I had to select the one I was interested by. So I have now:

ImageMagick.magickinfo("CT020072.JPG",( "exif:DateTime"))

Dict{String,Any} with 1 entries:
  "exif:DateTime" => "2020:12:07 09:22:04"

Which is exactly what I was looking for ! Thanks !

2 Likes

Would love it if someone would click Sign in to GitHub · GitHub

and edit the file to add a docstring! (Click the pencil icon)

1 Like

Tim,

I will take a stab at it. Not sure how complete my documentation will be, but anything is better than nothing.

Michael

1 Like

Tim,

When I moused over the pencil icon it says that I "must be on a branch to make or propose changes to this file.” I’m still a newbie with GitHub. Does this mean that I should make a fork, or is it a PR that I need to do? I had assumed that I could just edit the file in the browser from your link.

Michael

Tim,

Here are my proposed changes:

@doc raw"“”
magickinfo(file::Union{AbstractString,IO})

Reads an image file and returns an array of strings describing the property data in the image file.

Examples

> p = magickinfo("Image.jpeg")
63-element Array{String,1}:
"date:create"
"date:modify"
"exif:ApertureValue"
"exif:BrightnessValue"
"exif:ColorSpace"
"exif:ComponentsConfiguration""exif:DateTime"
"exif:DateTimeDigitized"
"exif:DateTimeOriginal"
"exif:ExifImageLength"
"exif:ExifImageWidth"
"exif:ExifOffset"
"exif:ExifVersion"
⋮
"exif:thumbnail:JPEGInterchangeFormat"
"exif:thumbnail:JPEGInterchangeFormatLength"
"exif:thumbnail:ResolutionUnit"
"exif:thumbnail:XResolution"
"exif:thumbnail:YResolution"
"exif:WhiteBalance"
"exif:XResolution"
"exif:YCbCrPositioning"
"exif:YResolution"
"jpeg:colorspace"
"jpeg:sampling-factor"
"unknown"a

“”"
function magickinfo(file::Union{AbstractString,IO})
wand = MagickWand()
readimage(wand, file)
resetiterator(wand)
getimageproperties(wand, “*”)
end

@doc raw"“”
magickinfo(file::Union{AbstractString,IO}, properties::Union{Tuple,AbstractVector})

Reads an image file and returns a Dict containing the values for the requested properties.

Examples

> magickinfo("IMG_6477.jpeg",
("exif:DateTime","exif:GPSLatitude","exif:GPSLatitudeRef",
"exif:GPSLongitude","exif:GPSLongitudeRef","exif:GPSAltitude"))
Dict{String,Any} with 6 entries:
"exif:GPSLongitudeRef" => "W"
"exif:GPSLatitude" => "44/1, 22/1, 2326/100"
"exif:GPSLatitudeRef" => "N"
"exif:GPSLongitude" => "71/1, 13/1, 5301/100"
"exif:DateTime" => "2020:01:22 13:17:41"
"exif:GPSAltitude" => "261189/757"

“”"
function magickinfo(file::Union{AbstractString,IO}, properties::Union{Tuple,AbstractVector})
wand = MagickWand()
readimage(wand, file)
resetiterator(wand)

props = Dict{String,Any}()
for p in properties
props[p] = getimageproperty(wand, p)
end
props
end

Tim,

I forked a branch, added the doc strings, and committed the changes. I’m not sure if anything else is needed for my changes to be seen by others.

Michael

Tim,

Sorry for this running commentary. I’ve created a PR. Now do I wait a day or so for comments and then Close Pull Request?

Michael

2 Likes

Thanks so much! It’s merged and should come out in a release later today!

3 Likes
2 Likes