Module: Smusher

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

Constant Summary collapse

MINIMUM_IMAGE_SIZE =

byte

20

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/smusher.rb', line 15

def optimize_image(files,options={})
  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)
      success = true
    end

    if success
      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



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

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