Skip to content

Instantly share code, notes, and snippets.

@janfri
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janfri/eb16e22a572fe2b57873 to your computer and use it in GitHub Desktop.
Save janfri/eb16e22a572fe2b57873 to your computer and use it in GitHub Desktop.
Read metadata with multi_exiftool and write it to a csv file
require 'csv'
require 'multi_exiftool'
tags = ["filename", "filesize", "make", "model", "orientation", "modifydate", "exposuretime", "fnumber", "exposureprogram", "iso", "createdate", "flash", "focallength", "quality", "canonflashmode", "continuousdrive", "focusmode", "lenstype", "cameratemperature", "cameratype", "canonimagetype", "canonfirmwareversion", "ownername", "cameraorientation", "focusdistanceupper", "focusdistancelower"]
# reading the data
reader = MultiExiftool::Reader.new
reader.tags = tags
reader.filenames = Dir['*.jpg']
results = reader.read
# writing to csv
CSV.open('output.csv', 'w') do |csv|
# write the header
csv << tags
# iterate over the results (res is a MultiExiftool::Values instance of one file)
results.each do |res|
# iterate over the tags and generate a new array of the values in res for each tag
values = tags.map {|tag| res[tag]}
# append it to the output
csv << values
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment