-
-
Save anonymous/32f33acaa69ad01e9484c390b6024a24 to your computer and use it in GitHub Desktop.
upload images along with auto-generated thumbnails to imgur and generate bbcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## resize and upload | |
set -eu | |
## if $1 is unset | |
if [ -z ${1+x} ]; then | |
echo "no argument given" | |
exit 1 | |
fi | |
# check if $img_file is a URL | |
url_regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' | |
if [[ $1 =~ $url_regex ]]; then | |
tmpfile='/tmp/teachat-imgur.jpg' | |
curl -o "$tmpfile" "$1" | |
imgpath="$tmpfile" | |
else | |
imgpath="$1" | |
fi | |
shrunkimgpath="/tmp/teachat-imgur-shrunk.jpg" | |
# teachat allows [img] to be max 640x1000 | |
# resize so that width is at most 600px and height is at most 950px | |
convert "$imgpath" -resize 600x950\> "$shrunkimgpath" | |
imgout=$(imgur-screenshot.sh "$imgpath") | |
imgshrunkout=$(imgur-screenshot.sh "$shrunkimgpath") | |
echo 'orig image:' | |
echo '----------' | |
echo "$imgout" | |
echo '----------' | |
echo 'shrunk image:' | |
echo '----------' | |
echo "$imgshrunkout" | |
echo '----------' | |
imgurl=$(echo "$imgout" | pcregrep -o1 'image link: (https?.+)') | |
imgshrunkurl=$(echo "$imgshrunkout" | pcregrep -o1 'image link: https?://(.+)') | |
# teachat needs [img] to be http and not https | |
imgshrunkurl="http://$imgshrunkurl" | |
teachatstr="[url=$imgurl][img]$imgshrunkurl[/img][/url]" | |
echo "$teachatstr" | |
echo -n "$teachatstr" | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment