From 4e5eb615606bef1619071ef89d4b34c20a7ac625 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Mon, 20 Mar 2023 09:48:56 +0800 Subject: Move image utilities into bin/ --- alias | 35 ----------------------------------- bin/image/shellrc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 bin/image/shellrc diff --git a/alias b/alias index 6931902..2481990 100644 --- a/alias +++ b/alias @@ -413,41 +413,6 @@ alias xii='`fc -ln -1` | head -1 | xsel -ib' alias xo='xsel -ob' alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob' -# image -image.vertical() { - suffix=${1##*.} - convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix} -} -image.horizontal() { - ext=${1##*.} - convert "$@" +append output.$ext -} -image.from_data_url() { - [[ $1 == '' ]] && echo File name needed && return 1 - xsel -ob | sed -E 's/^.+,//' | base64 -d >$1 - identify $1 -} -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 -} -image.text() { - convert \ - -size 230x130 \ - -background lightblue \ - -font Noto-Sans-Bold \ - -pointsize 25 \ - -fill black \ - -gravity Center \ - caption:"${1:=foo}" \ - -flatten \ - "${2:=foo}".jpg -} - # Reset clock date-reset() { sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" 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 @@ +# Image Utilities + +# Concatenate image vertically +image.vertical() { + suffix=${1##*.} + convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix} +} + +# 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 +} + +# 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 +} -- cgit v1.2.3-70-g09d2