class ImageOptimizer
Constants
- VERSION
Attributes
options[R]
path[R]
Public Class Methods
new(path, options = {})
click to toggle source
# File lib/image_optimizer.rb, line 22 def initialize(path, options = {}) @path = path @options = options end
quiet()
click to toggle source
# File lib/image_optimizer.rb, line 14 def self.quiet @@quiet end
quiet=(value)
click to toggle source
# File lib/image_optimizer.rb, line 17 def self.quiet=(value) @@quiet = value end
Public Instance Methods
optimize()
click to toggle source
# File lib/image_optimizer.rb, line 27 def optimize identify_format if options[:identify] JPEGOptimizer.new(path, options).optimize PNGOptimizer.new(path, options).optimize PNGQuantOptimizer.new(path, options).optimize GIFOptimizer.new(path, options).optimize end
Private Instance Methods
identify_bin()
click to toggle source
# File lib/image_optimizer.rb, line 60 def identify_bin ENV['IDENTIFY_BIN'] || which('identify') end
identify_bin?()
click to toggle source
# File lib/image_optimizer.rb, line 56 def identify_bin? !!identify_bin end
identify_format()
click to toggle source
# File lib/image_optimizer.rb, line 37 def identify_format if identify_bin? match = run_command("#{identify_bin} -ping#{quiet} #{path}").match(/PNG|JPG|TIFF|GIF|JPEG/) if match options[:identified_format] = match[0].downcase end else warn 'Attempting to retrieve image format without identify installed. Using file name extension instead...' end end
image_magick?()
click to toggle source
# File lib/image_optimizer.rb, line 52 def image_magick? !!which('mogrify') end
quiet()
click to toggle source
# File lib/image_optimizer.rb, line 48 def quiet ' -quiet' if image_magick? end