# Image Utilities # Concatenate image vertically image.vertical() { ext=${1##*.} convert "$@" -append $(basename -s .$ext $1)-$(basename -s .$ext ${@: -1}).${format:-$ext} } # Concatenate image horizontally image.horizontal() { ext=${1##*.} convert "$@" +append output.$ext } # Export image with data url format image.from_data_url() { [ -z "$1" ] && echo File name needed && return 1 xsel -ob | sed -E 's/^.+,//' | base64 -d >$1 identify $1 } # Resize image image.resize() { ext=${1##*.} convert -resize $2 $1 output.$ext } # Upload image to vps # Usage: # image.upload foo.png image.upload() { local month=$(date +%Y-%m) local filename=${2:-$(date +"%d_%Hh%Mm%Ss").${1##*.}} local fpath='$HOME/data/s3.photos/'$month cat $1 | ssh vps "mkdir -p $fpath && cat >$fpath/$filename" && \ echo https://topo.tw/photos/$month/$filename || \ echo Fail to upload } # Create an image contains text image.text() { convert \ -size 230x130 \ -background lightblue \ -font Noto-Sans-Bold \ -pointsize 25 \ -fill black \ -gravity Center \ caption:"${1:=foo}" \ -flatten \ "${2:=foo}".jpg }