Merge pull request #51480 from albus522/dg/improve-vips-analyzer
Be a lot more memory efficient analyzing images with ruby-vips
This commit is contained in:
commit
f613ba8f78
@ -19,13 +19,16 @@ def read_image
|
||||
|
||||
download_blob_to_tempfile do |file|
|
||||
image = instrument("vips") do
|
||||
# ruby-vips will raise Vips::Error if it can't find an appropriate loader for the file
|
||||
::Vips::Image.new_from_file(file.path, access: :sequential)
|
||||
rescue ::Vips::Error
|
||||
logger.info "Skipping image analysis because Vips doesn't support the file"
|
||||
nil
|
||||
end
|
||||
|
||||
if valid_image?(image)
|
||||
if image
|
||||
yield image
|
||||
else
|
||||
logger.info "Skipping image analysis because Vips doesn't support the file"
|
||||
{}
|
||||
end
|
||||
rescue ::Vips::Error => error
|
||||
@ -40,12 +43,5 @@ def rotated_image?(image)
|
||||
rescue ::Vips::Error
|
||||
false
|
||||
end
|
||||
|
||||
def valid_image?(image)
|
||||
image.avg
|
||||
true
|
||||
rescue ::Vips::Error
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user