Created
September 5, 2014 13:02
-
-
Save clemens/d835634afb5ad55f03ae 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
| task :optimize_pngs => 'optimize_pngs:setup' do | |
| dir = ENV['DIRECTORY'] || Rails.root.join('app/assets') | |
| from_extension = ENV['EXTENSION'] || '-optimize' | |
| to_extension = 'd.png' # -2x-optimize.png => -2x-optimized.png | |
| speed = ENV['SPEED'] || 1 | |
| files = Dir[dir.join("**/*#{from_extension}.png")] | |
| options = ["--ext #{to_extension}", "--speed #{speed}"] | |
| options << '--verbose' if ENV['VERBOSE'] == 'true' | |
| options << '--force' unless ENV['NO_FORCE'] == 'true' | |
| `pngquant #{options.join(' ')} #{files.join(' ')}` | |
| end | |
| namespace :optimize_pngs do | |
| task :setup do | |
| unless `which pngquant`.length > 0 | |
| puts 'pngquant not found - installing from homebrew ...' | |
| `brew update && brew install pngquant` | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment