Module: Sinicum::Imaging::Converter

Included in:
DefaultConverter, MaxSizeConverter, ResizeCropConverter
Defined in:
lib/sinicum/imaging/converter.rb

Overview

Collection of helper methods common to Converters

Constant Summary collapse

CONVERTER_VERSION =

change to change Hash signature

"1"
PNG_OPTIMIZER_SUFFIX =
"-fs8.png"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#document=(value) ⇒ Object (writeonly)

Sets the attribute document

Parameters:

  • value

    the value to set the attribute document to.



11
12
13
# File 'lib/sinicum/imaging/converter.rb', line 11

def document=(value)
  @document = value
end

Instance Method Details

#config_hashString

Computes a standard hash for a converted image, consisting of ‘x`, `y`, `render_type` and `format`.

Returns:

  • (String)

    A hash based on the current converter’s configuration



25
26
27
28
29
# File 'lib/sinicum/imaging/converter.rb', line 25

def config_hash
  digest = Digest::MD5.hexdigest(
    "#{@x}-#{@y}-#{@hires_factor}-#{@render_type}-#{@format}-#{CONVERTER_VERSION}")
  digest
end

#initialize(configuration) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sinicum/imaging/converter.rb', line 13

def initialize(configuration)
  @x = configuration['x'] || ''
  @y = configuration['y'] || ''
  @render_type = configuration['render_type']
  @hires_factor = configuration['hires_factor'] || 1.0
  @configuration = configuration
end

#interlace_option(x, y) ⇒ String

Returns the interlace command line option if an image is large enough (> 80px x 80px)

Parameters:

  • x (String, Fixnum)

    the x size of an image

  • y (String, Fixnum)

    the y size of an image

Returns:

  • (String)

    the command line option to interlace an image or an empty String



37
38
39
# File 'lib/sinicum/imaging/converter.rb', line 37

def interlace_option(x, y)
  x.to_i * y.to_i > 80 * 80 ? "-interlace plane" : ""
end

#ratio(x, y) ⇒ Object



41
42
43
# File 'lib/sinicum/imaging/converter.rb', line 41

def ratio(x, y)
  x.to_f / y.to_f
end