Created
August 27, 2012 03:05
-
-
Save nimbupani/3485220 to your computer and use it in GitHub Desktop.
Hacking Gyazo to save to AWS
This file contains 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'aws/s3' | |
# capture png file | |
tmpfile = "/tmp/image_upload#{$$}.png" | |
imagefile = ARGV[1] | |
if imagefile && File.exist?(imagefile) then | |
system "sips -s format png \"#{imagefile}\" --out \"#{tmpfile}\"" | |
else | |
system "screencapture -i \"#{tmpfile}\"" | |
if File.exist?(tmpfile) then | |
system "sips -d profile --deleteColorManagementProperties \"#{tmpfile}\"" | |
end | |
end | |
if !File.exist?(tmpfile) then | |
exit | |
end | |
imagedata = File.read(tmpfile) | |
File.delete(tmpfile) | |
AWS::S3::Base.establish_connection!( | |
:access_key_id => ENV['AMAZON_ACCESS_KEY_ID'], :secret_access_key => ENV['AMAZON_SECRET_ACCESS_KEY'] | |
) | |
filename = Time.now.to_i.to_s + '.png' | |
AWS::S3::S3Object.store(filename, imagedata, ENV['AMAZON_GYAZO_BUCKET_NAME'], :access => :public_read) | |
url = AWS::S3::S3Object.find(filename, ENV['AMAZON_GYAZO_BUCKET_NAME']).url(:authenticated => false) | |
system "echo -n #{url} | pbcopy" | |
system "open #{url}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment