Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple png + jpg optimization script using optipng + jpegtran
#!/usr/bin/ruby
# Instructions
# - Install optipng + libjpeg (http://mxcl.github.com/homebrew/)
# - Put this file in a directory of images
# - Open in TextMate + run it (cmd+r)
# Config
dir = `pwd`.strip
optipng = `which optipng`
jpegtran = `which jpegtran`
png = ".png"
jpg = ".jpg"
suffix = "-opt"
replace = false
# Optimize PNGs
p "Optimizing .pngs in #{dir}"
Dir.glob(dir + "/**/*#{png}", File::FNM_CASEFOLD).each do |f|
d = File.dirname(f)
n = "#{File.basename(f,File.extname(f))}#{suffix}#{png}"
o = "#{d}/#{n}"
if replace
p "- #{f}"
`#{optipng} #{f}`
else
p "- #{f} > #{o}"
`#{optipng} #{f} -out #{o}`
end
end
# Optimize JPGs
p "Optimizing .jpgs in #{dir}"
Dir.glob(dir + "/**/*#{jpg}", File::FNM_CASEFOLD).each do |f|
d = File.dirname(f)
n = "#{File.basename(f,File.extname(f))}#{suffix}#{jpg}"
o = "#{d}/#{n}"
if replace
p "- #{f}"
`#{jpegtran} -optimize #{f}`
else
p "- #{f} > #{o}"
`#{jpegtran} -optimize -outfile #{o} #{f}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.