The Shutter Imgur.com upload plugin stopped working recently, so I've been looking for alternatives and I stumbled upon Imgur-Screenshot, a bash script that can take screenshots and upload them to Imgur.
Imgur-Screenshot comes with quite a few handy features, including:
- automatically copies Imgur link to clipboard;
- allows editing the image (by using an external image editing app) before uploading;
- upload images anonymously or to an Imgur account;
- can create and add images to Imgur albums;
- uploaded images can be set to be deleted automatically after a configurable number of seconds;
- highly configurable.
The script can also upload any image to Imgur, so it's not just for uploading screenshots taken using Imgur-Screenshot. That's actually the part I was more interested in, especially since taking screenshots using scrot (SCReen shOT), which Imgur-Screenshot uses under the hood by default, is not that reliable lately.
However, Imgur-Screenshot does support using other screenshot tools, like maim (which Ubuntu / Linux Mint users can install from the main WebUpd8 PPA). This, along with other settings can be changed in the Imgur-Screenshot configuration file.
I'm using Imgur-Screenshot with a simple Nemo (also available for Nautilus and Caja) script to upload images to Imgur, which you can find below. Using this script, you can right click an image in Nautilus, Nemo or Caja and select Scripts > Upload to Imgur, which results in uploading the image to Imgur and copying the image URL to the clipboard.
Still, since some of you may want to use Imgur-Screenshot with scrot or maim, I'll include instructions for this below.
Install and use Imgur-screenshot
1. Download Imgur-screenshot
2. Install Imgur-Screenshot
To install the script in /usr/local/bin/, place the downloaded "imgur-screenshot.sh" file into your home directory and run the following commands:
cd
sudo install imgur-screenshot.sh /usr/local/bin/imgur-screenshot
The script can auto-update itself. When an update is available, you can update imgur-screenshot using the following commands:
sudo imgur-screenshot --update
sudo chmod 775 /usr/local/bin/imgur-screenshot
3. Install the Imgur-Screenshot dependencies
Imgur-Screenshot depends on libnotify-bin, scrot, xclip, curl and grep. To install them in Ubuntu / Linux Mint and derivatives, use the following command (some might already be installed):
sudo apt-get install libnotify-bin scrot xclip curl grep
You can use the following command to check the status of each dependency:
imgur-screenshot --check
To use Imgur-screenshot to take a screenshot and upload it to Imgur, simply run it from the command line, like this:
imgur-screenshot
... and select a window or a region to which you want to take a screenshot of.After taking the screenshot, Imgur-Screenshot automatically opens the Imgur image link in your default web browser and copies the image link to the clipboard.
The image link is also displayed in the command output, along with the delete link:
The image link is also displayed in the command output, along with the delete link:
You can also bind the script to a hotkey. For instance, under Unity, you can do this by going to System Settings > Keyboard > Shortcuts > Custom Shortcuts:
Here you can create a new custom shortcut, enter "imgur-screenshot" as the command and assign it a keyboard shortcut.
To see all the Imgur-Screenshot options, use:
imgur-screenshot --help
Optional: Configure Imgur-Screenshot
To be able to configure Imgur-Screenshot, you need to create a folder called "imgur-screenshot" in ~/.config/. To do this, you can use the following command:
mkdir -p ~/.config/imgur-screenshot/
And in this folder, create a file called settings.conf:touch ~/.config/imgur-screenshot/settings.conf
All the settings you enter in this file will overwrite the default Imgur-Screenshot settings. You can find all the available options, HERE.
By default, the images are stored in the ~/Pictures folder however, the folder name might be different if you don't use Ubuntu (or whatever Linux distribution you're using) in English.
To change the folder used by Imgur-Screenshot to store the screenshots, open ~/.config/imgur-screenshot/settings.conf with a text editor - I'll use Gedit below:
gedit ~/.config/imgur-screenshot/settings.conf
and in this file, paste the following:file_dir="$HOME/Pictures"
... and replace "Pictures" with the name of your pictures folder (or some other folder). The path can contain spaces.
Using the same configuration file (~/.config/imgur-screenshot/settings.conf), you can also change the tool used to take screenshots.
For instance, to use maim (which you can install from the main WebUpd8 PPA) instead of scrot, use the following in the configuration file:
screenshot_select_command="maim -s %img"
screenshot_window_command="maim %img"
You can even use Imgur-Screenshot with GNOME Screenshot, but only the "screenshot_select_command" will work.
To use GNOME Screenshot, use the following in the Imgur-Screenshot configuration file file:
screenshot_select_command="gnome-screenshot --area --file=%img"
Or, for Shutter (but note that Shutter needs to be closed for this to work), use the following in the ~/.config/imgur-screenshot/settings.conf file:
screenshot_select_command="shutter --select --exit_after_capture --output=%img"
If you're interested in connecting Imgur-Screenshot with your Imgur account, so all the images uploaded using this script are added to your account, here's how to do it:
1. To connect Imgur-screenshot to your Imgur account, must firstly register a new application on Imgur, at https://api.imgur.com/oauth2/addclient - select "OAuth 2 authorization without a callback URL", enter an application name, email and description and click "submit".
On the next page, a Client ID and Imgur Secret are displayed - copy these as you'll need them later.
2. Next, open the Imgur-Screenshot settings.conf file - I'll use Gedit below:
gedit ~/.config/imgur-screenshot/settings.conf
and in this file, paste the following:imgur_acct_key="YOUR_APP_CLIENT_ID"
imgur_secret="YOUR_APP_SECRET"
login="true"
... replacing YOUR_APP_CLIENT_ID and YOUR_APP_SECRET with the application client id and secret which you obtained by following step 1, and save the file.3. And finally, to authorize your Imgur app with Imgur-Screenshot, run the following command (the upload screenshot command also works):
imgur-screenshot -c
which should display an URL - copy the link and open it in a web browser. Next, copy the pin number displayed by this URL, go back to the terminal where you ran the command, paste the pin and press ENTER. That's it! Imgur-Screenshot should now upload screenshots to your Imgur account.
Optional: Nautilus, Nemo and Caja scripts for uploading images to Imgur using Imgur-Screenshot
Imgur-Screenshot is not only useful to take screenshots, but it can also upload images from your computer to Imgur. I found this feature useful and decided to simplify it so it can be used from Nautilus, Nemo and Caja, where you can right click an image and select Scripts > Upload to Imgur to achieve this.
"imgur-screenshot" needs to be available in $PATH for the scripts below to work. If not, you can enter the full path to imgur-screenshot.
Nautilus script:
#!/bin/bash
IFS=$'\n'
for FILENAME in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
if [ -f "$FILENAME" ]; then
imgur-screenshot "$FILENAME"
fi
done
To install this script for Nautilus, create a file called "Upload to Imgur" in ~/.local/share/nautilus/scripts/ (if the folder doesn't exist, create it) and paste the code above, then save the file and make it executable (right click the file and select Properties > Permissions > "Execute: Allow executing file as program").Nemo script:
#!/bin/bash
IFS=$'\n'
for FILENAME in $NEMO_SCRIPT_SELECTED_FILE_PATHS; do
if [ -f "$FILENAME" ]; then
imgur-screenshot "$FILENAME"
fi
done
To install this script for Nemo, create a file called "Upload to Imgur" in ~/.local/share/nemo/scripts/ (if the folder doesn't exist, create it) and paste the code above. Then save the file and make it executable (right click the file and select Properties > Permissions > "Execute: Allow executing file as program").Caja script:
#!/bin/bash
IFS=$'\n'
for FILENAME in $CAJA_SCRIPT_SELECTED_FILE_PATHS; do
if [ -f "$FILENAME" ]; then
imgur-screenshot "$FILENAME"
fi
done
To install this script for Caja, create a file called "Upload to Imgur" in ~/.config/caja/scripts/ (if the folder doesn't exist, create it) and paste the code above. Then save the file and make it executable (right click the file and select Properties > Permissions > "Execute: Allow executing file as program").