WIP add thumbnail CLI tools
This commit is contained in:
parent
aae26c510d
commit
05a76f2899
|
@ -45,6 +45,8 @@ to `slcl`. If required, encryption should be done before uploading e.g.: using
|
|||
- `xxd` (for [`usergen`](usergen) only).
|
||||
- `jq` (for [`usergen`](usergen) only).
|
||||
- CMake (optional).
|
||||
- `entr` (for [`watchdir`](watchdir) only).
|
||||
- ImageMagick (for [`tngen`](tngen) only).
|
||||
|
||||
### Ubuntu / Debian
|
||||
|
||||
|
@ -57,7 +59,7 @@ sudo apt install build-essential libcjson-dev libssl-dev
|
|||
#### Optional packages
|
||||
|
||||
```sh
|
||||
sudo apt install cmake xxd jq
|
||||
sudo apt install cmake xxd jq inotify-tools imagemagick
|
||||
```
|
||||
|
||||
## How to use
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
#! /bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "$0 [-s <size>] [-h] -d <dir> <path>"
|
||||
}
|
||||
|
||||
SIZE=96
|
||||
|
||||
while getopts s:d:h arg
|
||||
do
|
||||
case $arg in
|
||||
d) DIR="$OPTARG"
|
||||
;;
|
||||
s) SIZE="$OPTARG"
|
||||
;;
|
||||
h) usage
|
||||
exit 0
|
||||
;;
|
||||
?) usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$DIR" ]
|
||||
then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
F="$1"
|
||||
|
||||
gen()
|
||||
{
|
||||
IN="$1"
|
||||
OUT="$2"
|
||||
|
||||
if [ -z "$OUT" ]
|
||||
then
|
||||
echo Expected output filename >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if convert -thumbnail x$SIZE "$IN" "$OUT"
|
||||
then
|
||||
echo Created $OUT
|
||||
else
|
||||
echo Failed to create $OUT >&2
|
||||
fi
|
||||
}
|
||||
|
||||
while read f; do
|
||||
if [ "$f" != "" ]
|
||||
then
|
||||
THUMBNAIL=$(echo "$f" | sed "s,$DIR/user/,$DIR/thumbnails/,")
|
||||
gen "$f" "$THUMBNAIL"
|
||||
fi
|
||||
done <<-EOF
|
||||
$(find "$F" -type f \
|
||||
-a -iname '*.jpeg' \
|
||||
-o -iname '*.jpg' \
|
||||
-o -iname '*.png' \
|
||||
-o -iname '*.jpeg')
|
||||
EOF
|
|
@ -0,0 +1,52 @@
|
|||
#! /bin/sh
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "$0 [-s <size>] [-r] [-h] [-d <subdir>] <dir>"
|
||||
}
|
||||
|
||||
REGEN=0
|
||||
SIZE=96
|
||||
|
||||
while getopts rs:d:h arg
|
||||
do
|
||||
case $arg in
|
||||
r) REGEN=1
|
||||
;;
|
||||
s) SIZE="$OPTARG"
|
||||
;;
|
||||
h) usage
|
||||
exit 0
|
||||
;;
|
||||
d) SUBDIR="$OPTARG"
|
||||
;;
|
||||
?) usage >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR="$1"
|
||||
|
||||
[ "$REGEN" -eq 1 ] && "$(dirname $0)/tngen" \
|
||||
${SIZE:+-s$SIZE} \
|
||||
-d "$DIR" \
|
||||
"$DIR/user"
|
||||
|
||||
while :
|
||||
do
|
||||
F="$(inotifywait -e modify,move,create,delete \
|
||||
--format "%w%f" -qr "$DIR/user/")"
|
||||
sleep 1 # TODO: revisit this
|
||||
"$(dirname $0)/tngen" \
|
||||
${SIZE:+-s$SIZE} \
|
||||
-d "$DIR" \
|
||||
"$F"
|
||||
done
|
Loading…
Reference in New Issue