Created
October 15, 2009 23:02
-
-
Save mndoci/211368 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
| #!/usr/bin/ruby | |
| # from http://travis-whitton.blogspot.com/2009/10/crushing-pngs-with-ruby.html | |
| # usage crush.rb images | sh | |
| require 'fileutils' | |
| require 'find' | |
| input_dir = ARGV[0] | |
| rewrite_dir = "/tmp/crush/" | |
| raise("Usage #{$0} dirname") unless input_dir | |
| Dir.mkdir(rewrite_dir) unless test(?d, rewrite_dir) | |
| Find.find(input_dir) do |file| | |
| if file =~ /\.png$/ | |
| base_dir = File.dirname(file) | |
| base_file = File.basename(file) | |
| new_dir = rewrite_dir + base_dir | |
| FileUtils.mkdir_p(new_dir) unless test(?d, new_dir) | |
| puts(%Q!pngcrush -reduce -brute "#{file}" "#{new_dir}/#{base_file}"!) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment