Skip to content

Instantly share code, notes, and snippets.

@solisoft
Created September 8, 2011 06:24
Show Gist options
  • Save solisoft/1202766 to your computer and use it in GitHub Desktop.
Save solisoft/1202766 to your computer and use it in GitHub Desktop.
image processing
require 'base64'
require 'uri'
require 'net/http'
if ARGV[0]
data = Base64.encode64(IO.read(ARGV[0])) rescue nil
unless data.nil?
# First Resize to 640x>
options = "-resize '640x>'"
res = Net::HTTP.post_form(URI.parse('http://img.idfuze.com/api'), {'picture' => data, 'options' => options, 'output' => "o.jpg" })
# You should encode res.body and save the result to a file ...
# Then Create a 320x> version
options = "-resize '320x>'"
res = Net::HTTP.post_form(URI.parse('http://img.idfuze.com/api'), {'picture' => res.body, 'options' => options, 'output' => "o.jpg"})
# You should encode res.body and save the result to a file ...
# Then create a square Thumb 50x50
options = "-thumbnail '50x50^' -gravity center -crop 50x50+0+0 +repage"
res = Net::HTTP.post_form(URI.parse('http://img.idfuze.com/api'), {'picture' => res.body, 'options' => options, 'output' => "o.jpg"})
# You should encode res.body and save the result to a file ...
puts res.body
else
puts "ERROR : File #{ARGV[0]} not Found."
end
else
puts "ERROR : Usage : ruby avatar.rb <filename>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment