Class: ActiveStorage::HotCell::Server::Analyzers::Image::Magick

Inherits:
MagickOperation show all
Defined in:
lib/active_storage/hot_cell/server/analyzers/image/magick.rb

Overview

What ActiveStorage::Analyzer::ImageAnalyzer::ImageMagick does, moved out of the application: width and height from identify, with the dimensions swapped when the stored orientation is a quarter turn, the way the shared image analyzer does it.

The result is a superset — pages and animation, which the vips analyzer also reports — that the client analyzer slices to Rails' { width, height }. An input ImageMagick cannot decode exits identify non-zero, which raises MiniMagick::Error, and the cell answers unreadable.

Constant Summary collapse

ROTATED =

The orientation names identify reports for a quarter turn, matching Rails' rotated_image? on the ImageMagick path.

%w[ LeftTop RightTop RightBottom LeftBottom ].freeze

Constants inherited from Operation

Operation::CONTENT_TYPES

Instance Method Summary collapse

Instance Method Details

#perform(inputs, _outputs) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/active_storage/hot_cell/server/analyzers/image/magick.rb', line 26

def perform(inputs, _outputs)
  source, = inputs
  frames = identified(source.path)
  width, height, orientation = frames.first

  { **dimensions(width, height, orientation), pages: frames.size, animated: frames.size > 1,
    bytes: source.to_io.stat.size }
end