123456789_123456789_123456789_123456789_123456789_

Class: ActiveStorage::Analyzer::ImageAnalyzer::Vips

Overview

This analyzer relies on the third-party ruby-vips gem. Ruby-vips requires the / libvips system library.

Constant Summary

Class Attribute Summary

::ActiveStorage::Analyzer - Inherited

.analyze_later?

Implement this method in concrete subclasses.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

::ActiveStorage::Analyzer::ImageAnalyzer - Inherited

::ActiveStorage::Analyzer - Inherited

#metadata

Override this method in a concrete subclass.

#download_blob_to_tempfile

Downloads the blob to a tempfile on disk.

#instrument, #logger, #tmpdir

Constructor Details

This class inherits a constructor from ActiveStorage::Analyzer

Instance Method Details

#read_image (private)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/analyzer/image_analyzer/vips.rb', line 15

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 image
      yield image
    else
      {}
    end
  rescue ::Vips::Error => error
    logger.error "Skipping image analysis due to a Vips error: #{error.message}"
    {}
  end
rescue ::Vips::Error => error
  logger.error "Skipping image analysis due to an Vips error: #{error.message}"
  {}
end

#rotated_image?(image) ⇒ Boolean (private)

[ GitHub ]

  
# File 'activestorage/lib/active_storage/analyzer/image_analyzer/vips.rb', line 40

def rotated_image?(image)
  ROTATIONS === image.get("exif-ifd0-Orientation")
rescue ::Vips::Error
  false
end