diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-03-20 09:48:56 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-03-20 09:49:02 +0800 |
| commit | 4e5eb615606bef1619071ef89d4b34c20a7ac625 (patch) | |
| tree | 0ad75a3d0a1bcd6b6b16f28c3aeac659cfa14dc7 /bin/image | |
| parent | a3c048ab4dc5e6e480e0331ac682dd69376856dd (diff) | |
Move image utilities into bin/
Diffstat (limited to 'bin/image')
| -rw-r--r-- | bin/image/shellrc | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bin/image/shellrc b/bin/image/shellrc new file mode 100644 index 0000000..e27b485 --- /dev/null +++ b/bin/image/shellrc | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | # Image Utilities | ||
| 2 | |||
| 3 | # Concatenate image vertically | ||
| 4 | image.vertical() { | ||
| 5 | suffix=${1##*.} | ||
| 6 | convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix} | ||
| 7 | } | ||
| 8 | |||
| 9 | # Concatenate image horizontally | ||
| 10 | image.horizontal() { | ||
| 11 | ext=${1##*.} | ||
| 12 | convert "$@" +append output.$ext | ||
| 13 | } | ||
| 14 | |||
| 15 | # Export image with data url format | ||
| 16 | image.from_data_url() { | ||
| 17 | [ -z "$1" ] && echo File name needed && return 1 | ||
| 18 | xsel -ob | sed -E 's/^.+,//' | base64 -d >$1 | ||
| 19 | identify $1 | ||
| 20 | } | ||
| 21 | |||
| 22 | # Upload image to vps | ||
| 23 | # Usage: | ||
| 24 | # image.upload foo.png | ||
| 25 | image.upload() { | ||
| 26 | local month=$(date +%Y-%m) | ||
| 27 | local filename=${2:-$(date +"%d_%Hh%Mm%Ss").${1##*.}} | ||
| 28 | local fpath='$HOME/data/s3.photos/'$month | ||
| 29 | cat $1 | ssh vps "mkdir -p $fpath && cat >$fpath/$filename" && \ | ||
| 30 | echo https://topo.tw/photos/$month/$filename || \ | ||
| 31 | echo Fail to upload | ||
| 32 | } | ||
| 33 | |||
| 34 | # Create an image contains text | ||
| 35 | image.text() { | ||
| 36 | convert \ | ||
| 37 | -size 230x130 \ | ||
| 38 | -background lightblue \ | ||
| 39 | -font Noto-Sans-Bold \ | ||
| 40 | -pointsize 25 \ | ||
| 41 | -fill black \ | ||
| 42 | -gravity Center \ | ||
| 43 | caption:"${1:=foo}" \ | ||
| 44 | -flatten \ | ||
| 45 | "${2:=foo}".jpg | ||
| 46 | } | ||