[scripts/wastickers] Added stickerpack generator
This commit is contained in:
parent
ccdeb31204
commit
395ea4806d
|
@ -0,0 +1,54 @@
|
||||||
|
#!/bin/env zsh
|
||||||
|
#
|
||||||
|
## Enable MAX STRICTNESS mode
|
||||||
|
set -euo pipefail
|
||||||
|
setopt nomatch nullglob
|
||||||
|
|
||||||
|
# Make checking for command existence easier
|
||||||
|
command_exists() { whence -- "$@" &>/dev/null; }
|
||||||
|
|
||||||
|
# Create a temporary folder for pack generation which will be
|
||||||
|
# deleted at the very end of the process
|
||||||
|
cwd=$(pwd)
|
||||||
|
mkdir -p $cwd/tmp
|
||||||
|
|
||||||
|
# Make sure the webp processing tool is present
|
||||||
|
if ! command_exists cwebp; then
|
||||||
|
echo "cwebp not found; Make sure it is installed. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! command_exists zip; then
|
||||||
|
echo "zip not found; Make sure it is installed. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read the metadata we will pipe to `author.txt` and `title.txt`
|
||||||
|
# Seriously, why are these separate text file? At the very least
|
||||||
|
# store the metadata somewhere reasonable such as a JSON file.
|
||||||
|
vared -p 'Author: ' -c author
|
||||||
|
vared -p 'Pack name: ' -c pname
|
||||||
|
echo "$author" > "$cwd/tmp/author.txt"
|
||||||
|
echo "$pname" > "$cwd/tmp/title.txt"
|
||||||
|
|
||||||
|
for image in *.png *.jpg *.jpeg; do
|
||||||
|
cp "$image" "$cwd/tmp/"
|
||||||
|
done
|
||||||
|
|
||||||
|
cd "$cwd/tmp"
|
||||||
|
|
||||||
|
# Every copy of the images we made above will be converted
|
||||||
|
# into a webp, then the copy will be deleted.
|
||||||
|
# To make sure all images get a separate timestamp, we wait
|
||||||
|
# one second for every image.
|
||||||
|
for image in *.png *.jpg *.jpeg; do
|
||||||
|
cwebp -q 60 $image -o "$(date +%s).webp" > /dev/null 2>&1
|
||||||
|
rm -rf $image
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# Finally, pack up our stickers and clean up the temp dir
|
||||||
|
zip -r -j "$pname.wastickers" "$cwd/tmp";
|
||||||
|
mv "$cwd/tmp/$pname.wastickers" "$cwd";
|
||||||
|
cd "$cwd";
|
||||||
|
rm -rf "$cwd/tmp";
|
Loading…
Reference in New Issue