Ubuntu – How to take a screenshot and then upload the image to imgur through terminal

command line

I don't like the GUI way of taking screenshot,uploading it to imgur and get the uploaded link.

So what can I do to take a screenshot of my Ubuntu desktop, upload the screenshot to imgur.com and then get back the uploaded link from terminal?

All I have to do from terminal.

Best Answer

Take the screenshot of your desktop

gnome-screenshot was the default command-line tool on Ubuntu to take a screenshot.

gnome-screenshot -d 10

Delayed the screenshot action by 10 seconds,So that you can place the desired window on front within 10 seconds.The taken images are actually stored in ~/Pictures folder.

Upload the image to imgur.com

gedit ~/.bashrc

Add the below lines to the opened .bashrc file and then save it.

imgur() {
    for i in "$@"; do
        curl -# -F "image"=@"$i" -F "key"="4907fcd89e761c6b07eeb8292d5a9b2a" imgur.com/api/upload.xml|\
        grep -Eo '<[a-z_]+>http[^<]+'|sed 's/^<.\|_./\U&/g;s/_/ /;s/<\(.*\)>/\x1B[0;34m\1:\x1B[0m /'
    done
}

Source the .bashrc file,so that the changes can take effect,

source ~/.bashrc

The above script requires curl package to work.So install it by running

sudo apt-get install curl

Then run the below command to upload the image stored in the ~/Pictures folder to imgur.com,

imgur ~/Pictures/filename.png

Get the link of uploaded image

enter image description here

Source