Skip to content

Instantly share code, notes, and snippets.

@mndoci
Created October 15, 2009 23:02
Show Gist options
  • Select an option

  • Save mndoci/211368 to your computer and use it in GitHub Desktop.

Select an option

Save mndoci/211368 to your computer and use it in GitHub Desktop.
#!/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