You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.0 KiB
50 lines
1.0 KiB
#!/usr/bin/env ruby
|
|
|
|
# == Summary
|
|
# Generates a exifs.csv file from JPEGs in a directory
|
|
# and subdirectories.
|
|
#
|
|
# == Usage
|
|
# ./exif2csv.rb [path_to_images]
|
|
#
|
|
# If [path_to_images] is not entered, program will browse
|
|
# subfolders.
|
|
#
|
|
# == Version History
|
|
# v0.0.2 - current
|
|
# v0.0.1 - 2010/08/27
|
|
#
|
|
# == Issues
|
|
# - Includes empty lines for JPEGs with no exifs
|
|
|
|
require 'csv'
|
|
require 'rubygems'
|
|
require 'mini_exiftool'
|
|
|
|
class Exif2CSV
|
|
@@header = ['FocalLength', 'Aperture', 'ExposureTime', 'ISO', 'Lens']
|
|
|
|
def self.generate_csv(directory)
|
|
CSV.open('exifs.csv', 'wb') do |csv|
|
|
csv << @@header
|
|
Exif2CSV.get_images(directory).each do |image|
|
|
csv << Exif2CSV.read_exifs(image)
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
def self.get_images(directory)
|
|
Dir.glob(File.join(directory,'**','*.jpg'), File::FNM_CASEFOLD)
|
|
end
|
|
def self.read_exifs(photo)
|
|
exifs = MiniExiftool.new photo
|
|
exifs.to_hash.values_at(*@@header)
|
|
end
|
|
end
|
|
|
|
if ARGV.empty?
|
|
Exif2CSV.generate_csv '.'
|
|
else
|
|
Exif2CSV.generate_csv ARGV[0]
|
|
end
|
|
|