A simple Ruby script to generate a CSV file from all JPEG EXIF data within a directory
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

51 lines
1.0KB

  1. #!/usr/bin/env ruby
  2. # == Summary
  3. # Generates a exifs.csv file from JPEGs in a directory
  4. # and subdirectories.
  5. #
  6. # == Usage
  7. # ./exif2csv.rb [path_to_images]
  8. #
  9. # If [path_to_images] is not entered, program will browse
  10. # subfolders.
  11. #
  12. # == Version History
  13. # v0.0.2 - current
  14. # v0.0.1 - 2010/08/27
  15. #
  16. # == Issues
  17. # - Includes empty lines for JPEGs with no exifs
  18. require 'csv'
  19. require 'rubygems'
  20. require 'mini_exiftool'
  21. class Exif2CSV
  22. @@header = ['FocalLength', 'Aperture', 'ExposureTime', 'ISO', 'Lens']
  23. def self.generate_csv(directory)
  24. CSV.open('exifs.csv', 'wb') do |csv|
  25. csv << @@header
  26. Exif2CSV.get_images(directory).each do |image|
  27. csv << Exif2CSV.read_exifs(image)
  28. end
  29. end
  30. end
  31. private
  32. def self.get_images(directory)
  33. Dir.glob(File.join(directory,'**','*.jpg'), File::FNM_CASEFOLD)
  34. end
  35. def self.read_exifs(photo)
  36. exifs = MiniExiftool.new photo
  37. exifs.to_hash.values_at(*@@header)
  38. end
  39. end
  40. if ARGV.empty?
  41. Exif2CSV.generate_csv '.'
  42. else
  43. Exif2CSV.generate_csv ARGV[0]
  44. end