Quickly Share Screenshots to ImgBB from the Linux Command Line!
Table of Contents
The Annoyance of Sharing Screenshots
As an avid IRC user, I often want to share screenshots. Given IRC doesn't have the fancy features that Discord does, I can't just simply paste my screenshots. While services like ImgBB are great for quick hosting, the process usually involves more steps than I care for:
- Taking the screenshot (often saving to a file or copying to clipboard).
- Opening a web browser.
- Navigating to imgbb.com.
- Clicking "Upload", then finding the file or pasting.
- Waiting for the upload.
- Copying the desired link format.
- Pasting the link to IRC, Browser, etc..
This felt like too many manual steps interrupting my workflow. If you know me. You know I want as minimal effort as required so we can be quick fast! I needed a command-line solution!
The Solution: `imgbb` - A Bash Uploader Script
To scratch this itch, I created a Bash script, conveniently named `imgbb`, that leverages command-line tools (`curl`, `jq`, `xclip`) to automate the entire process.
With this script, I can copy an image to my clipboard (or specify a file path) and simply run `imgbb` in my terminal. It handles the upload, gets the direct image link, prints it, and copies it straight to my clipboard, ready to paste into IRC or anywhere else I might like.
The Script
If like me, you're often hosting images on imgBB and want to upload quickly, you can download the code from my Git repository. Be sure to check the README, even after reading this blog post, there may be some slight changed made.
Key Features
- Upload images directly from the X11 clipboard (attempts PNG then JPEG).
- Upload images directly from a specified file path.
- Set an optional auto-deletion expiration time using human-friendly durations (e.g.,
5m
,2h
,7d
) or set it to never expire (0
). Defaults to 2 hours if not specified. - Specify a custom filename for the uploaded image on ImgBB.
- Optionally output and copy the URL in Markdown format (

). - Copies the resulting URL to the X11 clipboard using
xclip
. - Provides optional desktop notifications using
notify-send
.
Dependencies: What You'll Need
The script relies on a few standard Linux tools. Make sure you have them installed:
bash
(v4+ recommended for features used)curl
(For web requests)jq
(For parsing the JSON response from ImgBB)xclip
(For accessing the X11 clipboard - Note: clipboard features won't work on Wayland, but IRC user dacav is working on that)notify-send
(Optional - for desktop pop-up notifications)- Standard
coreutils
(mktemp, basename, rm, cat, echo, etc.)
On Debian based distributions, you can install the main dependencies like this:
sudo apt update
sudo apt install curl jq xclip notify-send
Installation
-
Clone the repository from my Gitea instance:
git clone git@git.ritchiecunningham.co.uk:Rtch/imgbb-uploader.git cd imgbb-uploader
-
Make the script executable:
chmod +x imgbb
-
Link it to your path for easy access (e.g.,
~/.local/bin
):mkdir -p ~/.local/bin # Make sure you are in the cloned repo directory first. ln -s "$(pwd)/imgbb" ~/.local/bin/imgbb
(Ensure
~/.local/bin
is in your$PATH
environment variable).
Configuration: Your ImgBB API Key
You need a free API key from ImgBB for the script to work.
- Get your key from https://api.imgbb.com/.
-
Store the key:
-
File: Create a file containing *only your API key:
mkdir -p ~/.config/imgbb_uploader vi ~/.config/imgbb_uploader/api_key # Paste key here, save file chmod 600 ~/.config/imgbb_uploader/api_key # Restrict permissions
-
Usage Guide
Run the script from your terminal. Provide options before the optional filepath.
imgbb [options] [filepath]
Options:
Flag | Argument | Description |
---|---|---|
`[filepath]` | Optional path to image file. If omitted, uses clipboard. | |
`-e, –expire` | DURATION | Set expiration (e.g., 300s , 5m , 2h , 7d ). Use 0 for none. Default: 2h. |
`-n, –name` | NAME | Set custom filename for upload. |
`–markdown` | Output/copy URL in Markdown format:  |
|
`-h, –help` | Show help message. |
Examples:
# Upload from clipboard (expires in 2h) $ imgbb Image URL: https://i.ibb.co/YourLinkHere/image.png (URL copied to clipboard) # Upload file (expires in 2h) $ imgbb screenshot.png Using image from file: screenshot.png Image URL: https://i.ibb.co/AnotherLink/screenshot.png (URL copied to clipboard) # Upload from clipboard, expire in 10 minutes $ imgbb -e 10m Expiration set to 600 seconds (10m). Image URL: https://i.ibb.co/Link3/clipboard.png (URL copied to clipboard) # Upload from clipboard, never expire $ imgbb -e 0 Setting NO expiration. Image URL: https://i.ibb.co/Link4/clipboard_noexpire.png (URL copied to clipboard) # Upload file, custom name, Markdown output $ imgbb -n "My Cool Setup" --markdown ~/img/desktop.jpg Using image from file: /home/user/img/desktop.jpg Setting custom name to 'My Cool Setup'. Formatting as Markdown. Image URL:  (Markdown copied to clipboard)
Limitations & Future Work
- Currently, the script relies on
xclip
and therefore only works correctly for clipboard operations under X11 sessions. Adding Wayland support (usingwl-clipboard
) would be a good enhancement. Error handling could also potentially be expanded. (dacav from Libera.Chat IRC #hackers, requires this feature and is currently working on a patch. Thanks dacav!). - Change api_key file to a conf file for users to set their preferences without requiring to edit the source code. Some people may not want to use `~/.config/`, so allow the user to select for themselves with an additional command option.
- Potentially add support for uploading to personal webservers. Typically I like imgbb for temporary screenshots I intend to expire after a bit, and that means I don't need to direct someone to my personal server. But for permanent screenshots, I'd like to keep control of them on my own server rather than be subject to imgBB.