Automatically reduce image sizes with smushit

UPDATE: lossless image size reduction of whole folders reduces image sizes dramatically, lossless!
Great for logos/icons…, but does not work for gifs!

I put together a small script to automate smushing (as long as i cannot find a popper API).

ruby smush.rb where/to/save.png

requires ruby and rubygems

sudo gem install json

Store this into smush.rb

optional(if this task is to full/gets blocked):
cange the &task=89266837334214400 to something else or use random

def store_smushed_image(url,file),'w') do |f|
    f.puts smushed_image_data_for(url)

def smushed_image_data_for(url)
  require 'cgi'
  url = CGI.escape url
  require 'net/http'
  require 'rubygems'
  require 'json'
  http ='')
  path = "/ws.php?img=#{url}&task=89266837334214400&id=paste2"
  resp, data = http.get(path, nil)
  raise "oops #{resp}" unless resp.is_a? Net::HTTPOK
  path = "/#{JSON.parse(data)['dest']}"
  resp, data = http.get(path, nil)

url = ARGV[0] || ""
file = ARGV[1] || 'out.png'

2 thoughts on “Automatically reduce image sizes with smushit

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s