-
-
Save guidipolito/fe311b5c04fc8f4486d610604a35b1ae to your computer and use it in GitHub Desktop.
optimize all png and jpeg inside the actual directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# image_optimizer requires availability of | |
# - pngquant | |
# - optipng | |
# - jpegoptim | |
require "image_optimizer" | |
require 'parallel' | |
def image?(file) | |
file =~ /\.(jpe?g|png)$/ | |
end | |
files = `find`.split("\n").filter do |file| | |
image?(file) | |
end | |
def optimize(files) | |
files.each do |f| | |
# quality is measure for jpeg, level is the measure for png | |
ImageOptimizer.new(f, quality: 80, level: 3).optimize | |
end | |
end | |
Parallel.map(files.each_slice(10).to_a, in_processes: 6) { |f| optimize(f) } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment