Created
September 8, 2011 06:24
-
-
Save solisoft/1202766 to your computer and use it in GitHub Desktop.
image processing
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
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