Small script to upload an image from clipboard or file to imgbb.com. URL is then inserted directly into clipboard ready to be pasted to IRC or.. wherever.
https://ritchiecunningham.co.uk
![]() The configuration is stored under ~/.config/imgbb_uploader.conf. The file is simply sourced, so the configuration file can be a shell script. It just needs to assign the required variables. |
||
---|---|---|
imgbb | ||
LICENSE | ||
README.md |
ImgBB Upload Script (imgbb
)
A simple Bash script to quickly upload images from the system clipboard (X11) or a specified file directly to ImgBB using their v1 API. It retrieves the direct image URL, prints it to STDOUT, and copies it to the X11 clipboard.
Ideal for quickly sharing screenshots or images in environments like IRC without needing to manually use the website interface.
Author: Ritchie Cunningham ritchie@ritchiecunningham.co.uk
Version: 1.0 (as of 22/04/2025)
Features
- Upload images directly from the clipboard (PNG or JPEG).
- Upload images directly from a file path.
- Set an optional auto-deletion expiration time (e.g.,
5m
,2h
,7d
,0
for none). - 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.
- Provides desktop notifications for progress and success/failure (optional).
Dependencies
Make sure you have the following command-line tools installed:
- curl: Used for making the HTTP API request.
sudo apt install curl # Debian.
- jq: Used for parsing the JSON API response.
sudo apt install jq # Debian.
- xclip: Used for accessing the X11 clipboard. This script will not work on Wayland sessions.
sudo apt install xclip # Debian.
- notify-send (Optional): Used for desktop notifications. The script works without it but won't show popups.
sudo apt install notify-send # Debian (often in libnotify-bin).
Installation
- Clone the repository:
git clone git@git.ritchiecunningham.co.uk:Rtch/imgbb-uploader.git cd imgbb-uploader
- Make the script executable:
chmod +x imgbb
- Place in your PATH (Recommended): Create a symbolic link to the script from a directory in your
$PATH
for easy execution (e.g.,~/.local/bin
, ensure this is in your$PATH
).
Now you can just runmkdir -p ~/.local/bin ln -s "$(pwd)/imgbb" ~/.local/bin/imgbb
imgbb
from your terminal.
Configuration
This script requires a free API key from ImgBB:
- Go to https://api.imgbb.com/ and register or log in to get your key.
- Store the key in
.config/imgbb/uploader/api_key
.- File Create the directory and file, then paste only your API key inside:
mkdir -p ~/.config/imgbb_uploader nano ~/.config/imgbb_uploader/api_key # Paste your key, save the file. # Set permissions so only you can read it: chmod 600 ~/.config/imgbb_uploader/api_key
- File Create the directory and file, then paste only your API key inside:
Usage
Options:
[filepath]
: Optional path to an image file to upload. If omitted, uses the clipboard content.-e, --expire DURATION
: Set auto-deletion timeout. DURATION is a number followed bys
(econds),m
(inutes),h
(ours), ord
(ays) (e.g.,5m
,2h
,7d
,300s
). Range: 60s-180d. Use0
,none
, ornever
for no expiration (overrides the default). Default expiration is 2 hours (7200s) if this option is not used.-n, --name NAME
: Set a custom filename for the uploaded image on ImgBB.--markdown
: Output and copy the URL in Markdown image format:
-h, --help
: Show the help message and exit.
Examples:
# Upload image from clipboard, expire in 2 hours (default)
imgbb
# Upload specific image file, expire in 2 hours
imgbb screenshot.png
# Upload from clipboard, expire in 10 minutes
imgbb -e 10m
# Upload from clipboard, never expire
imgbb -e 0
# Upload file, give it a name on ImgBB, get Markdown output/copy
imgbb -n "Cool Diagram" --markdown diagram.jpg
# Show help
imgbb -h
# Notes
Currently relies on xclip and therefore only works reliably under X11 sessions. Wayland support would require adding logic to use wl-clipboard.
# License
This project is licensed under the GPL License. See the LICENSE file for details. (Action: You need to add a file named LICENSE to your repository containing the text of the GPL, likely GPLv3).