How to use imgbb API for for command line image hosting

Dejak Madina
1 min readJun 3, 2021

Here’s a little, easy tutorial I’ve written for those API lovers for using imgbb API for command line photo hosting.

My requirements were that the script had to work on both Linux and macOS and not require any third-party modules because I didn’t want to have to keep them updated on different operating systems. There are some nice Python scripts but they require the requests module (which is great, but is third-party). Likewise while the right thing to do is parse the JSON response with something like jq, that’s a third-party dependency, so I’ll just munge it with a regex.

Domain Name Registration Web Hosting

Here’s code showing how easy it is.

First, create an account on imgbb.com and then login with it. Then visit api.imgbb.com and click “Get API Key”.

Here’s the script I’m using, which is modified from the example on their site:

#!/bin/bash

# change this to your actual API KEY
API_KEY=123451234512345
RESPONSE=$(curl -s --location \
--request POST "https://api.imgbb.com/1/upload?key=${API_KEY}" \
--form "image=@$1")
URL=$(echo $RESPONSE | sed 's/^.*"display_url":"//' | sed 's/",.*$//')
URL=$(echo $URL | sed 's#\\/#/#g')
echo $URL

Here’s the output:

$ ~/Dropbox/bin/imgbb_upload.sh ~/Desktop/leb_logo.png 
https://i.ibb.co/zmhDzKS/leb-logo.png

That URL is now suitable for use on any forum.

--

--