Forked from morewry/compass-config-with-png-compression.rb
Last active
August 29, 2015 14:10
-
-
Save mgillman/2e39927f87f608da71a3 to your computer and use it in GitHub Desktop.
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
project_path = File.dirname(__FILE__) + "/" | |
utils_dir = "utilities/" | |
utils_path = project_path + utils_dir | |
# callback - on_sprite_saved | |
# http://compass-style.org/help/tutorials/configuration-reference/ | |
on_sprite_saved do |filename| | |
if File.exists?(filename) | |
# Post process sprite image | |
postprocesspng(filename, utils_path) | |
end | |
end | |
# fn - Post processing for pngs | |
# http://compass-style.org/help/tutorials/configuration-reference/ | |
# http://pngquant.org/ | |
# http://advsys.net/ken/utils.htm & http://nicj.net/2012/05/15/pngoutbatch | |
# http://optipng.sourceforge.net/ | |
def postprocesspng(filename, utils_path) | |
if File.exists?(filename) | |
sleep 1 | |
optimize(filename, utils_path + "pngquant/pngquant --verbose --force --ext .png 256") | |
optimize(filename, utils_path + "pngout/pngoutbatch.cmd") | |
optimize(filename, utils_path + "optipng/optipng -o7 -verbose") | |
end | |
end | |
# fn - Run optimize command line for a specified script | |
# https://gist.github.com/2403117 | |
def optimize(filename, script) | |
if File.exists?(filename) | |
sleep 1 | |
system script + " " + filename | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment