aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-03-20 09:48:56 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-03-20 09:49:02 +0800
commit4e5eb615606bef1619071ef89d4b34c20a7ac625 (patch)
tree0ad75a3d0a1bcd6b6b16f28c3aeac659cfa14dc7
parenta3c048ab4dc5e6e480e0331ac682dd69376856dd (diff)
Move image utilities into bin/
-rw-r--r--alias35
-rw-r--r--bin/image/shellrc46
2 files changed, 46 insertions, 35 deletions
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'
413alias xo='xsel -ob' 413alias xo='xsel -ob'
414alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob' 414alias xl='history | tail -1 | grep -oP "^\s*[0-9]+\s\s\K.*" | xsel -ib && echo Copied to clipboard && xsel -ob'
415 415
416# image
417image.vertical() {
418 suffix=${1##*.}
419 convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix}
420}
421image.horizontal() {
422 ext=${1##*.}
423 convert "$@" +append output.$ext
424}
425image.from_data_url() {
426 [[ $1 == '' ]] && echo File name needed && return 1
427 xsel -ob | sed -E 's/^.+,//' | base64 -d >$1
428 identify $1
429}
430image.upload() {
431 local month=$(date +%Y-%m)
432 local filename=${2:-$(date +"%d_%Hh%Mm%Ss").${1##*.}}
433 local fpath='$HOME/data/s3.photos/'$month
434 cat $1 | ssh vps "mkdir -p $fpath && cat >$fpath/$filename" && \
435 echo https://topo.tw/photos/$month/$filename || \
436 echo Fail to upload
437}
438image.text() {
439 convert \
440 -size 230x130 \
441 -background lightblue \
442 -font Noto-Sans-Bold \
443 -pointsize 25 \
444 -fill black \
445 -gravity Center \
446 caption:"${1:=foo}" \
447 -flatten \
448 "${2:=foo}".jpg
449}
450
451# Reset clock 416# Reset clock
452date-reset() { 417date-reset() {
453 sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" 418 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 @@
1# Image Utilities
2
3# Concatenate image vertically
4image.vertical() {
5 suffix=${1##*.}
6 convert "$@" -append $(basename -s .$suffix $1)-$(basename -s .$suffix ${@: -1}).${format:-$suffix}
7}
8
9# Concatenate image horizontally
10image.horizontal() {
11 ext=${1##*.}
12 convert "$@" +append output.$ext
13}
14
15# Export image with data url format
16image.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
25image.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
35image.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}