Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module ActiveStorage
# This analyzer relies on the third-party {MiniMagick}[https://github.com/minimagick/minimagick] gem. MiniMagick requires
# the {ImageMagick}[http://www.imagemagick.org] system library.
class Analyzer::ImageAnalyzer::ImageMagick < Analyzer::ImageAnalyzer
def self.accept?(blob)
super && ActiveStorage.variant_processor == :mini_magick
end

private
def read_image
download_blob_to_tempfile do |file|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module ActiveStorage
# This analyzer relies on the third-party {ruby-vips}[https://github.com/libvips/ruby-vips] gem. Ruby-vips requires
# the {libvips}[https://libvips.github.io/libvips/] system library.
class Analyzer::ImageAnalyzer::Vips < Analyzer::ImageAnalyzer
def self.accept?(blob)
super && ActiveStorage.variant_processor == :vips
end

private
def read_image
download_blob_to_tempfile do |file|
Expand Down
16 changes: 14 additions & 2 deletions activestorage/test/analyzer/image_analyzer/image_magick_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ class ActiveStorage::Analyzer::ImageAnalyzer::ImageMagickTest < ActiveSupport::T
end
end

test "analyzing with ruby-vips unavailable" do
stub_const(Object, :Vips, Module.new) do
analyze_with_image_magick do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
metadata = extract_metadata_from(blob)

assert_equal 4104, metadata[:width]
assert_equal 2736, metadata[:height]
end
end
end

test "instrumenting analysis" do
blob = create_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")

Expand All @@ -60,12 +72,12 @@ class ActiveStorage::Analyzer::ImageAnalyzer::ImageMagickTest < ActiveSupport::T

private
def analyze_with_image_magick
previous_analyzers, ActiveStorage.analyzers = ActiveStorage.analyzers, [ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick]
previous_processor, ActiveStorage.variant_processor = ActiveStorage.variant_processor, :mini_magick

yield
rescue LoadError
ENV["BUILDKITE"] ? raise : skip("Variant processor image_magick is not installed")
ensure
ActiveStorage.analyzers = previous_analyzers
ActiveStorage.variant_processor = previous_processor
end
end
4 changes: 2 additions & 2 deletions activestorage/test/analyzer/image_analyzer/vips_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class ActiveStorage::Analyzer::ImageAnalyzer::VipsTest < ActiveSupport::TestCase

private
def analyze_with_vips
previous_analyzers, ActiveStorage.analyzers = ActiveStorage.analyzers, [ActiveStorage::Analyzer::ImageAnalyzer::Vips]
previous_processor, ActiveStorage.variant_processor = ActiveStorage.variant_processor, :vips

yield
rescue LoadError
ENV["BUILDKITE"] ? raise : skip("Variant processor vips is not installed")
ensure
ActiveStorage.analyzers = previous_analyzers
ActiveStorage.variant_processor = previous_processor
end
end