Browse Source

feat: add heic images support to the organizer

Lukasz Badura 3 months ago
parent
commit
5353b546a9
3 changed files with 13 additions and 4 deletions
  1. 5 0
      Rakefile
  2. 1 1
      lib/fotos/asset.rb
  3. 7 3
      lib/fotos/organizer.rb

+ 5 - 0
Rakefile

@@ -5,4 +5,9 @@ require "minitest/test_task"
 
 
 Minitest::TestTask.create
 Minitest::TestTask.create
 
 
+desc 'install and run'
+task :run => :install do
+  sh 'fotos organize -s ~/Downloads/bemol-2025/bemol-2025-hania -d ~/Desktop/bemol-test'
+end
+
 task default: :test
 task default: :test

+ 1 - 1
lib/fotos/asset.rb

@@ -1,7 +1,7 @@
 module Fotos
 module Fotos
   class Asset
   class Asset
     THUMBNAIL_PREFIX = "TH_"
     THUMBNAIL_PREFIX = "TH_"
-    SUPPORTED_TYPES = ['.JPEG', '.JPG']
+    SUPPORTED_TYPES = ['.JPEG', '.JPG', '.HEIC']
 
 
     def initialize(file_path)
     def initialize(file_path)
       @file_path = file_path
       @file_path = file_path

+ 7 - 3
lib/fotos/organizer.rb

@@ -1,8 +1,10 @@
-require 'exifr/jpeg'
 require 'fileutils'
 require 'fileutils'
+require 'vips'
 
 
 module Fotos
 module Fotos
   class Organizer
   class Organizer
+    VIPS_DATE_FIELD = 'exif-ifd2-DateTimeOriginal'
+
     def initialize(options)
     def initialize(options)
       @source_path = options[:source]
       @source_path = options[:source]
       @destination_path = options[:destination]
       @destination_path = options[:destination]
@@ -16,10 +18,12 @@ module Fotos
         puts "looking at #{asset.file_name}"
         puts "looking at #{asset.file_name}"
         next unless asset.supported?
         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
         # 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_dir = File.join(@destination_path, exif_date_str)
         dest_path = File.join(dest_dir, asset.file_name)
         dest_path = File.join(dest_dir, asset.file_name)