Module: Smusher

Extended by:
Smusher
Included in:
Smusher
Defined in:
lib/smusher.rb,
lib/smusher/puny_png.rb,
lib/smusher/smush_it.rb

Defined Under Namespace

Classes: PunyPng, SmushIt

Constant Summary collapse

MINIMUM_IMAGE_SIZE =

byte

20
VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip

Instance Method Summary collapse

Instance Method Details

#optimize_image(files, options = {}) ⇒ Object

optimize the given image converts gif to png, if size is lower can be called with a file-path or an array of files-paths



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/smusher.rb', line 20

def optimize_image(files,options={})
  service = options[:service] || 'SmushIt'
  service = eval(service)

  Array(files).each do |file|
    check_options(options)
    puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero?

    with_logging(file, options[:quiet]) do
      write_optimized_data(file, service)
    end
  end
end

#optimize_images_in_folder(folder, options = {}) ⇒ Object

fetch all jpg/png images from given folder and optimize them



35
36
37
38
39
40
# File 'lib/smusher.rb', line 35

def optimize_images_in_folder(folder, options={})
  check_options(options)
  images_in_folder(folder, options[:convert_gifs]).each do |file|
    optimize_image(file, options)
  end
end