Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require ruby-vips before downloading blob #45448

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 9 additions & 7 deletions activestorage/lib/active_storage/analyzer/image_analyzer/vips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ def self.accept?(blob)

private
def read_image
download_blob_to_tempfile do |file|
begin
require "ruby-vips"
rescue LoadError
logger.info "Skipping image analysis because the ruby-vips gem isn't installed"
return {}
end

download_blob_to_tempfile do |file|
image = instrument("vips") do
::Vips::Image.new_from_file(file.path, access: :sequential)
end
Expand All @@ -23,13 +28,10 @@ def read_image
logger.info "Skipping image analysis because Vips doesn't support the file"
{}
end
rescue ::Vips::Error => error
logger.error "Skipping image analysis due to an Vips error: #{error.message}"
{}
end
rescue LoadError
logger.info "Skipping image analysis because the ruby-vips gem isn't installed"
{}
rescue ::Vips::Error => error
logger.error "Skipping image analysis due to an Vips error: #{error.message}"
{}
end

ROTATIONS = /Right-top|Left-bottom|Top-right|Bottom-left/
Expand Down