This gem is the simplest thing that could possibly work that reads the output of exiftool and renders it into a ruby hash, with correctly typed values and symbolized keys.
Ruby 3.1 through 3.3 are supported.
Future releases of exiftool
Gem will no longer support following
Ruby Versions due to their End Of Life announcements:
The latest Exiftool is recommended, but you’ll get that automatically by using the exiftool_vendored gem!
method_missing
madnessrequire 'exiftool'
e = Exiftool.new("path/to/iPhone 4S.jpg")
e.to_hash
# => {:make => "Apple", :gps_longitude => -122.47566667, …
e.to_display_hash
# => {"Make" => "Apple", "GPS Longitude" => -122.47566667, …
This gem supports Exiftool’s multiget, which lets you fetch metadata for many files at once.
This can be dramatically more efficient than spinning up the exiftool
process for each file due to the cost of spinning up perl.
Supply an array to the Exiftool initializer, then use .result_for
:
require 'exiftool'
e = Exiftool.new(Dir["**/*.jpg"])
result = e.result_for("path/to/iPhone 4S.jpg")
result.to_hash
# => {:make => "Apple", :gps_longitude => -122.47566667, …
result[:gps_longitude]
# => -122.47566667
Or iterate through files_with_results:
e.files_with_results
# => ["path/to/iPhone 4S.jpg", "path/to/Droid X.jpg", …
It seems that most exif dates don’t include timezone offsets, without which forces us to assume the current timezone is applicable to the image, which isn’t necessarily correct.
To be correct, we punt and return the exiftool-formatted string, which will be something like
%Y:%m:%d %H:%M:%S
.
If the clock was set correctly on your camera, the date will be the correct calendar day
as far as you were concerned when you took the photo. Given that, we
add a _civil
key associated to just the calendar date of the field, which should be safe-ish.
require 'exiftool'
e = Exiftool.new("test/IMG_2452.jpg")
e[:date_time_original]
=> "2011:07:06 09:46:45"
e[:date_time_original_civil]
=> #<Date: 2011-07-06 ((2455749j,0s,0n),+0s,2299161j)>
Exiftool::NoSuchFile
is raised if the provided filename doesn’t exist.Exiftool::ExiftoolNotInstalled
is raised if exiftool
isn’t in your PATH
.#errors?
will return true:Exiftool.new("Gemfile").errors?
#=> true
The easiest way is to use the “vendored” exiftool in the exiftool_vendored gem. Just add
gem 'exiftool_vendored'
to your Gemfile, run bundle
, and you’re done. (Note that it depends on the exiftool
gem,
so really, you’re done! Skip step 2!)
If you want to install exiftool on your system yourself:
brew install exiftool
sudo apt-get install libimage-exiftool-perl
If you didn’t use exiftool_vendored
, then add this your Gemfile:
gem 'exiftool'
and then run bundle
.
If you have exiftool installed outside of ruby’s PATH
, add an initializer that points the gem
to the tool, like this: Exiftool.command = '/home/ruby/Image-ExifTool-9.33/exiftool'
. You don’t need to do
this if you’ve installed added the exiftool directory to the PATH of the shell that runs ruby.
NameError
related to pathname
standard library when multiget is usedrubocop-minitest
and rubocop-rake
for better styleguide coverageexiftool_installed?
, referenced by issue #11.Support Pathname
instances as constructor args.
Addresses issue #8
Dropped official support for jruby due to CI failures.
-n
(force numeric values)#raw_hash
to Exiftool::Result
to support columns that can have parsing issues,
like dates that don’t include timezone offsets..exiftool_version
is now a string rather than a float,
which didn’t work so well with version numbers like “9.40”Exiftool.command
Fixed homepage URL in gemspec
Added support for multiple file fetching (which is much faster for large directories)