Browse Source

Thumbnail generator uses Asset as input. Removed console output from thumbnail generation.

Lukasz Badura 5 months ago
parent
commit
aa20e308ce
2 changed files with 6 additions and 19 deletions
  1. 1 1
      lib/fotos/html_generator.rb
  2. 5 18
      lib/fotos/thumbnail.rb

+ 1 - 1
lib/fotos/html_generator.rb

@@ -18,7 +18,7 @@ module Fotos
             puts "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
             puts "<a href=\"#{asset.path}\"><img src=\"#{asset.thumbnail_path}\" /></a>"
           else
           else
             if @generate_thumbnails
             if @generate_thumbnails
-              Fotos::Thumbnail.new(asset.path).create
+              Fotos::Thumbnail.new(asset).create
               redo
               redo
             end
             end
             puts "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"
             puts "<a href=\"#{asset.dirname}/#{asset.file_name}\"><img src=\"#{asset.path}\" /></a>"

+ 5 - 18
lib/fotos/thumbnail.rb

@@ -1,32 +1,19 @@
 require 'image_science'
 require 'image_science'
 module Fotos
 module Fotos
   class Thumbnail
   class Thumbnail
-    def initialize(path)
-      @path = path
-      @input_filename = File.basename(path)
+    def initialize(asset)
+      @asset = asset
     end
     end
 
 
     def create
     def create
-      if File.exist?(thumbnail_path)
-        puts "Thumbnail exists for #{@input_filename}"
+      if File.exist?(@asset.thumbnail_path)
       else
       else
-        puts "Creating #{thumbnail_filename}"
-        ImageScience.with_image(@path) do |img|
+        ImageScience.with_image(@asset.file_path) do |img|
           img.thumbnail(250) do |thumb|
           img.thumbnail(250) do |thumb|
-            thumb.save(thumbnail_path)
+            thumb.save(@asset.thumbnail_path)
           end
           end
         end
         end
       end
       end
     end
     end
-
-    private
-
-    def thumbnail_filename
-      "TH_#{@input_filename}"
-    end
-
-    def thumbnail_path
-      File.join(File.dirname(@path), thumbnail_filename)
-    end
   end
   end
 end
 end