Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # Settings
- browser_cmd = 'firefox'
- clipboard_cmd = 'xclip'
- proxy_addr = nil
- proxy_port = nil
- require 'net/http'
- idfile = ENV['HOME'] + "/.gyazo.id"
- if (`which import`).strip.size == 0
- $stderr.puts "Please install imagemagick to use gyazo utility"
- Process.exit
- end
- id = ''
- if File.exist?(idfile) then
- id = File.read(idfile).chomp
- else
- id = Time.new.strftime("%Y%m%d%H%M%S")
- File.open(idfile,"w").print(id+"\n")
- end
- tmpfile = "/tmp/image_upload#{$$}.png"
- imagefile = ARGV[0]
- if imagefile && File.exist?(imagefile) then
- system "convert #{imagefile} #{tmpfile}"
- else
- system "import #{tmpfile}"
- end
- imagedata = File.read(tmpfile)
- File.delete(tmpfile)
- boundary = '----BOUNDARYBOUNDARY----'
- HOST = 'gyazo.com'
- CGI = '/upload.cgi'
- data = <<EOF
- --#{boundary}\r
- content-disposition: form-data; name="id"\r
- \r
- #{id}\r
- --#{boundary}\r
- content-disposition: form-data; name="imagedata"\r
- \r
- #{imagedata}\r
- \r
- --#{boundary}--\r
- EOF
- header ={
- 'Content-Length' => data.length.to_s,
- 'Content-type' => "multipart/form-data; boundary=#{boundary}"
- }
- Net::HTTP::Proxy(proxy_addr, proxy_port).start(HOST,80) {|http|
- res = http.post(CGI,data,header)
- url = res.response.to_ary[1]
- puts url
- if system "which #{clipboard_cmd} >/dev/null 2>&1" then
- system "echo #{url} | #{clipboard_cmd}"
- end
- system "#{browser_cmd} #{url}"
- }
Add Comment
Please, Sign In to add comment