Last active
August 29, 2015 14:03
-
-
Save janfri/eb16e22a572fe2b57873 to your computer and use it in GitHub Desktop.
Read metadata with multi_exiftool and write it to a csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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