Skip to content

Instantly share code, notes, and snippets.

@lavie
Created February 14, 2012 18:19
Show Gist options
  • Save lavie/1828787 to your computer and use it in GitHub Desktop.
Save lavie/1828787 to your computer and use it in GitHub Desktop.
Upload image to imgurl and copy remote URL into clipboard
import sys
import urllib2
from json import loads
from urllib import urlencode
import base64
print sys.argv
LOG_FILE = 'uploads.log'
DEV_KEY = 'YOUR KEY HERE' # from http://imgur.com/register/api_anon
def add_to_clipboard(str):
from Tkinter import Tk
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(str)
r.destroy()
def upload(local):
img = open(local, "rb").read()
b64 = base64.encodestring(img)
data = urlencode({
"image" : b64,
"key" : DEV_KEY
})
request = urllib2.Request("http://api.imgur.com/2/upload.json", data)
try:
response = urllib2.urlopen(request).read()
json = loads(response)
remote = json["upload"]["links"]["original"]
except urllib2.HTTPError, e:
print e
return remote
def main():
if len(sys.argv) < 2:
print """
Usage:
snagurl.py <local-file>
"""
return 1
local = sys.argv[1]
print "Processing %s" % local
remote = upload(local)
print "Uploaded to: %s" % remote
add_to_clipboard(remote)
f = open(LOG_FILE, 'a')
f.write("%s -> %s\n" % (local, remote))
if __name__ == '__main__':
main()
@tyilo
Copy link

tyilo commented Nov 26, 2013

How would I set this up? Your blog post isn't very specific when it just says Then configure SnagIt to output into this script as a program. You might need to wrap it with a CMD file, depending on your local python setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment