Class: Poleica::Converters::GraphicsMagick

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/poleica/converters/graphics_magick/graphics_magick.rb,
lib/poleica/converters/graphics_magick/convert_options_generator.rb,
lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb

Overview

The GraphicsMagick converter, use the ‘gm’ command to convert images and documents

Defined Under Namespace

Classes: ConvertOptionsGenerator, ThumbnailOptionsGenerator

Constant Summary collapse

COMPATIBLE_TYPES =
[
  Types::Image,
  Types::PDF
]
DEFAULT_MEASURE =
612

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils

#bin_path, exec_with_timeout, extract_extension_and_options, fail_if_error, #host_os, init_process_std, #linux?, map_std, #osx?, #underscorize, #windows?

Constructor Details

#initialize(polei) ⇒ GraphicsMagick

Returns a new instance of GraphicsMagick.



18
19
20
# File 'lib/poleica/converters/graphics_magick/graphics_magick.rb', line 18

def initialize(polei)
  @polei = polei
end

Instance Attribute Details

#poleiObject (readonly)

Returns the value of attribute polei.



16
17
18
# File 'lib/poleica/converters/graphics_magick/graphics_magick.rb', line 16

def polei
  @polei
end

Instance Method Details

#to_png(options = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/poleica/converters/graphics_magick/graphics_magick.rb', line 22

def to_png(options = {})
  opts_gen = ConvertOptionsGenerator.new(polei, options)
  exec_with_timeout(bin_path, opts_gen.generate)
  expected_file_path = opts_gen.output_path
  File.exist?(expected_file_path) ? expected_file_path : nil
end

#to_thumbnail(options = {}) ⇒ Object



29
30
31
32
33
34
# File 'lib/poleica/converters/graphics_magick/graphics_magick.rb', line 29

def to_thumbnail(options = {})
  opts_gen = ThumbnailOptionsGenerator.new(polei, options)
  exec_with_timeout(bin_path, opts_gen.generate)
  expected_file_path = opts_gen.output_path
  File.exist?(expected_file_path) ? expected_file_path : nil
end