From a517b8ba00c7783994ada714ce382f02e6f36f4b Mon Sep 17 00:00:00 2001 From: Chris Gaffney Date: Tue, 17 Dec 2024 12:29:21 -0500 Subject: [PATCH] Support test matchers with only Vips This adds support for using the test matchers when neither MiniMagick or Magick are installed. --- lib/carrierwave/test/matchers.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/carrierwave/test/matchers.rb b/lib/carrierwave/test/matchers.rb index cf4057667..e2bdb24dd 100644 --- a/lib/carrierwave/test/matchers.rb +++ b/lib/carrierwave/test/matchers.rb @@ -336,6 +336,8 @@ class ImageLoader # :nodoc: def self.load_image(filename) if defined? ::MiniMagick MiniMagickWrapper.new(filename) + elsif defined? ::Vips + VipsWrapper.new(filename) else unless defined? ::Magick begin @@ -393,6 +395,28 @@ def initialize(filename) end end + class VipsWrapper # :nodoc: + attr_reader :image + + def width + image.width + end + + def height + image.height + end + + def format + # This returns the name of the vips loader (e.g. pngload) as Vips + # doesn't do content detection. + image.get("vips-loader").delete_suffix("load") + end + + def initialize(filename) + @image = ::Vips::Image.new_from_file(filename) + end + end + end # Matchers end # Test end # CarrierWave