Module: Smusher
Constant Summary collapse
- MINIMUM_IMAGE_SIZE =
byte
20
Instance Method Summary collapse
-
#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.
-
#optimize_images_in_folder(folder, options = {}) ⇒ Object
fetch all jpg/png images from given folder and optimize them.
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,={}) files.each do |file| () puts "THIS FILE IS EMPTY!!! #{file}" and return if size(file).zero? success = false with_logging(file,[: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,={}) () images_in_folder(folder,[:convert_gifs]).each do |file| optimize_image(file) end end |