aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/image/shellrc
blob: e27b48557f46ed1cd98ecda610b219bdeac4e76d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}