Skip to content

Instantly share code, notes, and snippets.

@nimbupani
Created August 27, 2012 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimbupani/3485220 to your computer and use it in GitHub Desktop.
Save nimbupani/3485220 to your computer and use it in GitHub Desktop.
Hacking Gyazo to save to AWS
#!/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