Class: Sinicum::Imaging::ResizeCropConverter

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

Overview

Internal: Resizes an image to an exact given size and crops anything else.

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) ⇒ ResizeCropConverter

Returns a new instance of ResizeCropConverter.



11
12
13
14
15
16
17
# File 'lib/sinicum/imaging/resize_crop_converter.rb', line 11

def initialize(configuration)
  if !configuration['format'] || !configuration['x'] || !configuration['y']
    fail ArgumentError.new("Converter requires the arguments: format, x, y")
  end
  super(configuration)
  @format = configuration['format'] || 'jpeg'
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



9
10
11
# File 'lib/sinicum/imaging/resize_crop_converter.rb', line 9

def format
  @format
end

Instance Method Details

#convert(infile_path, outfile_path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/sinicum/imaging/resize_crop_converter.rb', line 19

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

#converted_sizeObject



30
31
32
# File 'lib/sinicum/imaging/resize_crop_converter.rb', line 30

def converted_size
  [@x, @y]
end