[scripts/wastickers] Added stickerpack generator

This commit is contained in:
Alyxia Sother 2021-07-02 17:37:48 +02:00
parent ccdeb31204
commit 395ea4806d
No known key found for this signature in database
GPG Key ID: 355968D14144B739
1 changed files with 54 additions and 0 deletions

54
scripts/wastickers Executable file
View File

@ -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";