class Poleica::Converters::GraphicsMagick::ThumbnailOptionsGenerator
Generate options for the GraphicsMagick
to_thumbnail @options page [Array, Integer]
Attributes
current_height[R]
current_width[R]
options[R]
output_path[R]
polei[R]
Public Class Methods
new(polei, options = {})
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 11 def initialize(polei, options = {}) @polei = polei @options = default_options.merge(options) @current_width, @current_height = identify end
Public Instance Methods
generate()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 17 def generate [ 'convert', "#{polei.path}[0]", orient_options, resize_options, output_options ].flatten end
Private Instance Methods
default_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 29 def default_options { path: polei.path_with_md5(:png), height: DEFAULT_MEASURE, width: DEFAULT_MEASURE, auto_orient: true } end
height_only_option()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 66 def height_only_option if percent(current_height, options[:height]) > 50 "x#{options[:height]}!" else "#{current_width}x#{current_height}" end end
identify()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 74 def identify line = exec_with_timeout(bin_path(GraphicsMagick), identify_options) width, height = line.split.first.split('x') [width.to_i, height.to_i] end
identify_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 80 def identify_options [ 'identify', '-format', '%wx%h ', polei.path ] end
orient_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 38 def orient_options @orient_options ||= options[:auto_orient] ? '-auto-orient' : '' end
output_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 93 def output_options @output_path = if File.directory?(options[:path]) name = File.basename(polei.path_with_md5(:png)) File.join(options[:path], name) else options[:path] end end
percent(comparing, compared)
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 89 def percent(comparing, compared) (comparing.to_f / compared.to_f) * 100 end
resize_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 42 def resize_options @resize_options ||= [ '-resize', "#{width_and_height_options}" ] end
width_and_height_options()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 50 def width_and_height_options if current_width >= current_height width_only_option else height_only_option end end
width_only_option()
click to toggle source
# File lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb, line 58 def width_only_option if percent(current_width, options[:width]) > 50 "#{options[:width]}!x" else "#{current_width}x#{current_height}" end end