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
33
34
35
36
37
38
39
# 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?
    success = false

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

    if success and service.converts_gif_to_png?
      gif = /\.gif$/
      `mv #{file} #{file.sub(gif,'.png')}` if file =~ gif
    end
  end
end

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

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



42
43
44
45
46
47
# File 'lib/smusher.rb', line 42

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