Class: Riiif::ImagemagickCommandFactory
- Inherits:
-
Object
- Object
- Riiif::ImagemagickCommandFactory
- Defined in:
- app/services/riiif/imagemagick_command_factory.rb
Overview
Builds a command to run a transformation using Imagemagick
Instance Attribute Summary collapse
-
#compression ⇒ Object
readonly
Returns the value of attribute compression.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#transformation ⇒ Object
readonly
Returns the value of attribute transformation.
Class Method Summary collapse
-
.build(path, transformation, compression: 85) ⇒ String
A helper method to instantiate and invoke build.
Instance Method Summary collapse
-
#build ⇒ String
A command for running imagemagick to produce the requested output.
-
#initialize(path, transformation, compression:) ⇒ ImagemagickCommandFactory
constructor
A helper method to instantiate and invoke build.
Constructor Details
#initialize(path, transformation, compression:) ⇒ ImagemagickCommandFactory
A helper method to instantiate and invoke build
17 18 19 20 21 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 17 def initialize(path, transformation, compression:) @path = path @transformation = transformation @compression = compression end |
Instance Attribute Details
#compression ⇒ Object (readonly)
Returns the value of attribute compression.
23 24 25 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 23 def compression @compression end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
23 24 25 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 23 def path @path end |
#transformation ⇒ Object (readonly)
Returns the value of attribute transformation.
23 24 25 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 23 def transformation @transformation end |
Class Method Details
.build(path, transformation, compression: 85) ⇒ String
A helper method to instantiate and invoke build
9 10 11 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 9 def self.build(path, transformation, compression: 85) new(path, transformation, compression: compression).build end |
Instance Method Details
#build ⇒ String
Returns a command for running imagemagick to produce the requested output.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/riiif/imagemagick_command_factory.rb', line 26 def build command = 'convert' command << " -crop #{transformation.crop}" if transformation.crop command << " -resize #{transformation.size}" if transformation.size if transformation.rotation command << " -virtual-pixel white +distort srt #{transformation.rotation}" end case transformation.quality when 'grey' command << ' -colorspace Gray' when 'bitonal' command << ' -colorspace Gray' command << ' -type Bilevel' end command << " -quality #{compression}" if use_compression? command << " #{path} #{transformation.format}:-" command end |