kobel/assets/build/images.sh

31 lines
691 B
Bash
Raw Normal View History

2024-01-11 20:04:55 +00:00
#!/bin/bash
# Libary needed: ImageMagick
PARAMS=('-quality 60')
2024-01-11 20:04:55 +00:00
if [ $# -ne 0 ]; then
PARAMS=$@;
fi
cd $(pwd)
shopt -s nullglob nocaseglob extglob
shopt -s globstar
# Resize
sizes=(320 640 960 1280)
for FILE in public/**/*.@(jpg|jpeg|tif|tiff|png|gif); do
DIR=$(dirname "$FILE")
NAME=$(basename "$FILE" | cut -d. -f1)
EXTENSION=$(basename "$FILE" | cut -d. -f2)
for size in ${sizes[@]}; do
convert "$FILE" -resize ${size}x${size}\> "${DIR}/${NAME}-${size}.${EXTENSION}"
done
done
2024-01-11 20:04:55 +00:00
# Web Optimized Formats
for FILE in public/**/*.@(jpg|jpeg|tif|tiff|png|gif); do
2024-01-11 20:08:31 +00:00
convert $PARAMS "$FILE" "${FILE}".webp;
convert $PARAMS "$FILE" "${FILE}".avif;
2024-01-11 20:04:55 +00:00
done