Class: Riiif::ImagemagickCommandFactory

Inherits:
Object
  • Object
show all
Defined in:
app/services/riiif/imagemagick_command_factory.rb

Overview

Builds a command to run a transformation using Imagemagick

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, transformation, compression:) ⇒ ImagemagickCommandFactory

A helper method to instantiate and invoke build

Parameters:

  • path (String)

    the location of the file

  • transformation (Transformation)
  • compression (Integer)

    the compression level to use (set 0 for no compression)



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

#compressionObject (readonly)

Returns the value of attribute compression.



23
24
25
# File 'app/services/riiif/imagemagick_command_factory.rb', line 23

def compression
  @compression
end

#pathObject (readonly)

Returns the value of attribute path.



23
24
25
# File 'app/services/riiif/imagemagick_command_factory.rb', line 23

def path
  @path
end

#transformationObject (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

Parameters:

  • path (String)

    the location of the file

  • transformation (Transformation)
  • compression (Integer) (defaults to: 85)

    (85) the compression level to use (set 0 for no compression)

Returns:

  • (String)

    a command for running imagemagick to produce the requested output



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

#buildString

Returns a command for running imagemagick to produce the requested output.

Returns:

  • (String)

    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