First commit
This commit is contained in:
50
exif2csv.rb
Normal file
50
exif2csv.rb
Normal file
@ -0,0 +1,50 @@
|
||||
#!/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
|
Reference in New Issue
Block a user