Skip to content

Instantly share code, notes, and snippets.

@morewry
Forked from kswedberg/snippet.rb
Created November 26, 2012 20:14
Show Gist options
  • Save morewry/4150334 to your computer and use it in GitHub Desktop.
Save morewry/4150334 to your computer and use it in GitHub Desktop.
Compass config with pngquant, pngout, and optipng to compress sprite
compiletype = environment
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)
if (compiletype == :production)
# Post process sprite image
postprocesspng(filename, utils_path)
end
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 -iebug -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