2 Commits 1fadcf7409 ... b0594c7fdd

Author SHA1 Message Date
  Lukasz Badura b0594c7fdd feat: automatically convert heic files to jpg upon running organize 3 months ago
  Lukasz Badura 0ec45fb7bd helper rake tasks to test 3 months ago
6 changed files with 34 additions and 11 deletions
  1. 13 4
      Rakefile
  2. 2 1
      bin/fotos
  3. 8 0
      lib/fotos/asset.rb
  4. 1 1
      lib/fotos/html_generator.rb
  5. 9 4
      lib/fotos/organizer.rb
  6. 1 1
      lib/fotos/thumbnail.rb

+ 13 - 4
Rakefile

@@ -5,10 +5,19 @@ require "minitest/test_task"
 
 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'
-  sh 'fotos build -s ~/Desktop/bemol-test -d ~/Desktop/bemol-web'
+desc 'install and run organize'
+task :test_organize => :install do
+  sh 'fotos organize -s ~/Downloads/bemol-2025/bemol-2025-hania -d ~/Desktop/bemol-test'
+end
+
+desc 'install and run build'
+task :test_build => :install do
+  sh 'fotos build -s ~/Desktop/bemol-test -d ~/Desktop/bemol-test -t'
+end
+
+desc 'cleanup'
+task :cleanup do
+  sh 'rm -rf ~/Desktop/bemol-test'
 end
 
 task default: :test

+ 2 - 1
bin/fotos

@@ -24,7 +24,8 @@ when 'build'
   parser.on('-t', '--thumbnails', 'Automatically generate missing thumbnails')
   options = {dest: '.'}
   parser.parse!(into: options)
-  Fotos::HtmlGenerator.new(options).call
+  html = Fotos::HtmlGenerator.new(options).call
+  File.write(File.join(options[:dest], 'index.html'), html)
 else
   puts "Unknown command! Available commands: #{COMMANDS.join(',')}."
   exit(-1)

+ 8 - 0
lib/fotos/asset.rb

@@ -44,6 +44,14 @@ module Fotos
       file_name.match?(THUMBNAIL_PREFIX)
     end
 
+    def file_base
+      file_name.split('.').first
+    end
+
+    def heic?
+      ext_name.match?(/heic/i)
+    end
+
     def web_supported?
       WEB_TYPES.include?(ext_name.upcase)
     end

+ 1 - 1
lib/fotos/html_generator.rb

@@ -22,7 +22,7 @@ module Fotos
         assets.reject(&:is_thumbnail?).each do |asset|
           ensure_thumbnail(asset)
 
-          if File.exist?(asset.thumbnail_path(@dest_dir.path))
+          if File.exist?(File.join(@dest_dir.path, asset.thumbnail_path))
             html_output << "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
           else
             html_output << "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"

+ 9 - 4
lib/fotos/organizer.rb

@@ -19,13 +19,18 @@ module Fotos
         exif_date_str = asset.exif_date.strftime(Fotos::DATE_FORMAT)
 
         dest_dir = File.join(@destination_path, exif_date_str)
-        dest_path = File.join(dest_dir, asset.file_name)
-
         # create destination dir if not already there
         FileUtils.mkdir_p(dest_dir) unless Dir.exist?(dest_dir)
+
+        if asset.web_supported?
+          dest_path = File.join(dest_dir, asset.file_name)
+          FileUtils.cp(fp, dest_path)
+        elsif asset.heic?
+          target_file_name = [asset.file_base, '.JPG'].join
+          dest_path = File.join(dest_dir, target_file_name)
+          asset.image.write_to_file(dest_path)
+        end
         puts "#{asset.file_name} --> #{dest_path}"
-        FileUtils.cp(fp, dest_path)
-        dest_path
       end
     end
   end

+ 1 - 1
lib/fotos/thumbnail.rb

@@ -7,7 +7,7 @@ module Fotos
     end
 
     def create(destination_path = ".")
-      target_path = @asset.thumbnail_path(destination_path)
+      target_path = File.join(destination_path, @asset.thumbnail_path)
       return target_path if File.exist?(target_path)
       th_image = Vips::Image.thumbnail(@asset.file_path, WIDTH)
       th_image.write_to_file(target_path)