Class: Sinicum::Imaging::MaxSizeConverter

Inherits:
Object
  • Object
show all
Includes:
Converter, Logger
Defined in:
lib/sinicum/imaging/max_size_converter.rb

Overview

Internal: Resizes an image to a predefined maximum size.

Constant Summary

Constants included from Converter

Converter::CONVERTER_VERSION, Converter::PNG_OPTIMIZER_SUFFIX

Instance Attribute Summary collapse

Attributes included from Converter

#document

Instance Method Summary collapse

Methods included from Logger

included, #logger

Methods included from Converter

#config_hash, #interlace_option, #ratio

Constructor Details

#initialize(configuration) ⇒ MaxSizeConverter

Returns a new instance of MaxSizeConverter.



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

def initialize(configuration)
  super(configuration)
  @format = configuration['format'] || 'jpeg'
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



8
9
10
# File 'lib/sinicum/imaging/max_size_converter.rb', line 8

def format
  @format
end

Instance Method Details

#convert(infile_path, outfile_path) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/sinicum/imaging/max_size_converter.rb', line 15

def convert(infile_path, outfile_path)
  x = device_pixel_size(@x)
  y = device_pixel_size(@y)
  special = '-background transparent' if @format == 'png'
  command = "convert #{infile_path} #{interlace_option(x, y)} #{special} " \
    "#{quality_option} " +
    "-resize #{x}x#{y} #{outfile_path}"
  `#{command}`
  optimize_png_outfile(outfile_path)
end

#converted_sizeObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sinicum/imaging/max_size_converter.rb', line 26

def converted_size
  original_ratio = ratio(@document.width, @document.height)
  x = @x.to_f
  y = @y.to_f
  if @y != '' && x / original_ratio > y
    x = (y * original_ratio).round
  else
    y = (x / original_ratio).round
  end
  [x, y]
end