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/ --- bin/image/shellrc | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bin/image/shellrc (limited to 'bin/image/shellrc') 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