Browse Source

feat: use vips instead of image_science to generate thumbnails to
support heic

Lukasz Badura 3 months ago
parent
commit
296615a0e1
2 changed files with 12 additions and 6 deletions
  1. 2 6
      lib/fotos/thumbnail.rb
  2. 10 0
      test/test_thumbnail.rb

+ 2 - 6
lib/fotos/thumbnail.rb

@@ -1,4 +1,3 @@
-require 'image_science'
 module Fotos
   class Thumbnail
     WIDTH = 250
@@ -10,11 +9,8 @@ module Fotos
     def create(destination_path = ".")
       target_path = @asset.thumbnail_path(destination_path)
       return target_path if File.exist?(target_path)
-      ImageScience.with_image(@asset.file_path) do |img|
-        img.thumbnail(WIDTH) do |thumb|
-          thumb.save(target_path)
-        end
-      end
+      th_image = Vips::Image.thumbnail(@asset.file_path, WIDTH)
+      th_image.write_to_file(target_path)
       target_path
     end
   end

+ 10 - 0
test/test_thumbnail.rb

@@ -16,4 +16,14 @@ class TestThumbnail < Minitest::Test
     # clean up previously created thumbnail
     File.unlink thumbnail.path
   end
+
+  def test_create_thumbnail_from_heic
+    target_path = Fotos::Thumbnail.new(@heic_asset).create()
+    thumbnail = Fotos::Asset.new(target_path)
+    assert Fotos::Thumbnail::WIDTH >= thumbnail.image.get('width')
+
+    # clean up previously created thumbnail
+    File.unlink thumbnail.path
+  end
+
 end