Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created January 8, 2014 20:42
Show Gist options
  • Save coderofsalvation/8324242 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8324242 to your computer and use it in GitHub Desktop.
uploads images e too imgur.com, returns url on success, 1 otherwise (bash function)
# uploads images e too imgur.com, returns url on success, 1 otherwise
# @dependancy curl
function uploadimg()
{
[ -z "$1" ] && return 1
for img
do
if [ -f "$img" ] ; then
case "$img" in
*.jpg|*.JPG|*.jpeg|*.png|*.PNG)
if [ -f /usr/bin/xclip ]; then
curl -s -F "image=@$img" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml \
| egrep -o "<original_image>(.)*</original_image>" | \
egrep -o "http://i.imgur.com/[^<]*" | tee /dev/fd/2 | xclip
else
curl -s -F "image=@$img" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml \
| egrep -o "<original_image>(.)*</original_image>" | \
egrep -o "http://i.imgur.com/[^<]*"
fi
;;
*)
return 1
;;
esac
else
return 1
fi
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment