Last Updated: February 25, 2016
· dlion

Imgur shell uploader

function imgur()

    response=$(curl -F "key=$apikey" -H "Expect: " -F "image=@$1" \
        http://imgur.com/api/upload.xml 2>/dev/null)
# the "Expect: " header is to get around a problem when using this through the
# Squid proxy. Not sure if it's a Squid bug or what.
if [ $? -ne 0 ]; then
        echo "Upload failed" >&2
        exit 2
elif [ $(echo $response | grep -c "<error_msg>") -gt 0 ]; then
        echo "Error message from imgur:" >&2
        echo $response | sed -r 's/.*<error_msg>(.*)<\/error_msg>.*/\1/' >&2
        exit 3

# parse the response and output our stuff
url=$(echo $response | sed -r 's/.*<original_image>(.*)<\/original_image>.*/\1/')
echo $(echo $url | grep "http://")

It's a simple function to upload your image in imgur site.
If you want use it for screenshot for example you can put it in your .bashrc and recall this with alias:

alias screenshot="import -pause 5 /tmp/screenshot.jpg ; imgur /tmp/screenshot.jpg ; rm -f /tmp/screenshot.jpg"

You receive on the screen the url of the image.

Say Thanks