-
-
Notifications
You must be signed in to change notification settings - Fork 198
Open
Description
Script to Upload Images to IMGBB with and without API
Hi,
I want to share my minimalist simple bash
scripts that allows Ksnip users to automatically upload their saved screenshots to IMGBB with and without API key and get the direct URL copied clipboard. This could be a useful for users who frequently share screenshots online directly and need alternative to Imgue broken for some time now.
Dependency:
curl
, to make theHTTP POST
request to IMGBB to upload the imagejq
, for parsing the JSON responsexclip
, for copying to the clipboard
Upload without API key:
#!/bin/bash
# Script: imgbb_up.sh
# Description: Uploads a local image to IMGBB without API key and appends
# the image URL and delete URL to a log file in the user's
# home directory and copy the image URL to the clipboard.
# Author: smed79
output_file="$HOME/imgbb.log" # File to store the output
# Make the call to IMGBB to upload the image
result=$(curl -s -X POST "https://imgbb.com/json" \
-F "source=@\"$1\"" \
-F "type=file" \
-F "action=upload" \
-F "name=image")
# Extract the image URL from the JSON response
image_url=$(echo "$result" | jq -r '.image.url')
# Extract the delete URL from the JSON response
delete_url=$(echo "$result" | jq -r '.image.delete_url')
# Output data to log file (date & time, image URL, delete URL, empty line for better readability)
echo -e "$(date "+%Y.%m.%d - %H:%M:%S")\n$image_url\n$delete_url\n" >> "$output_file"
# Copy the image URL to the clipboard using xclip
echo -n "$image_url" | xclip -selection clipboard
Upload with api key:
Get your API key from https://api.imgbb.com/
(account required).
#!/bin/bash
# Script: imgbb_up.sh
# Description: Uploads a local image to IMGBB with API key and appends
# the image URL and delete URL to a log file in the user's
# home directory and copy the image URL to the clipboard.
# Dependency: curl, jq, xclip
# Author: smed79
api_key="0000000000000000000000000000000" # Replace with your actual IMGBB API key
output_file="$HOME/imgbb.log" # File to store the output
# Make the API call to IMGBB to upload the image
result=$(curl -s --location --request POST "https://api.imgbb.com/1/upload?key=${api_key}" \
--form "image=@\"$1\"" \
--form "name=image")
# Extract the image URL from the JSON response using jq
image_url=$(echo "$result" | jq -r '.data.url')
# Extract the delete URL from the JSON response using jq
delete_url=$(echo "$result" | jq -r '.data.delete_url')
# Output data to log file (date & time, image URL, delete URL, empty line for better readability)
echo -e "$(date "+%Y.%m.%d - %H:%M:%S")\n$image_url\n$delete_url\n" >> "$output_file"
# Copy the image URL to the clipboard using xclip
echo -n "$image_url" | xclip -selection clipboard
How to Use with Ksnip:
- Save the script to a location on your system (e.g.,
~/scripts/imgbb_upload.sh
). - Make it executable:
chmod +x ~/scripts/imgbb_upload.sh
. - In Ksnip's settings, change "Uploader Type" to "Script".
- In "Script Uploader" field, enter:
/path/to/your/script/imgbb_upload.sh
- Click "OK" to ensure the configuration is saved.
The script, as provided,
- uploads the image to IMGBB server
- save "
image URL
" & "delete URL
" with "date+time
" to imgbb.log file. - copy the "
image URL
" to the clipboard.
Limitations:
- Basic Error Handling: Doesn't robustly manage potential failures during upload or processing.
- No Progress Feedback: Users lack visual indication of the upload status.
- External Tool Dependency: Requires
curl
,jq
, andxclip
to be present. - Ignores IMGBB Errors: Doesn't interpret specific error messages from the image host.
- Insecure API Key Storage: API key is directly written in the script.
Note:
The IMGBB "delete URL
" should be kept private, as anyone with it can remove the image.
I hope this is helpful.
navjotjsingh
Metadata
Metadata
Assignees
Labels
No labels