|
|
@@ -1,8 +1,10 @@
|
|
|
-require 'exifr/jpeg'
|
|
|
require 'fileutils'
|
|
|
+require 'vips'
|
|
|
|
|
|
module Fotos
|
|
|
class Organizer
|
|
|
+ VIPS_DATE_FIELD = 'exif-ifd2-DateTimeOriginal'
|
|
|
+
|
|
|
def initialize(options)
|
|
|
@source_path = options[:source]
|
|
|
@destination_path = options[:destination]
|
|
|
@@ -16,10 +18,12 @@ module Fotos
|
|
|
puts "looking at #{asset.file_name}"
|
|
|
next unless asset.supported?
|
|
|
|
|
|
- exif = EXIFR::JPEG.new(fp)
|
|
|
+ image = Vips::Image.new_from_file(fp)
|
|
|
+ exif_date_data = image.get_value(VIPS_DATE_FIELD).split(' ')[0..1].join(':')
|
|
|
+ dt_attrs = exif_date_data.split(':').map(&:to_i)
|
|
|
|
|
|
# get date from file's exif data
|
|
|
- exif_date_str = exif.date_time.strftime(Fotos::DATE_FORMAT)
|
|
|
+ exif_date_str = DateTime.new(*dt_attrs).strftime(Fotos::DATE_FORMAT)
|
|
|
|
|
|
dest_dir = File.join(@destination_path, exif_date_str)
|
|
|
dest_path = File.join(dest_dir, asset.file_name)
|