55 lines
1.9 KiB
Bash
Executable File
55 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Normalise toutes les icônes de html/assets/icons
|
|
# - PNG/JPG → WebP 60x60 max, source supprimée
|
|
# - WebP trop grands → redimensionnés
|
|
# - WebP déjà conformes → ignorés
|
|
#
|
|
# Usage : ./convert-icon.sh [dossier]
|
|
set -euo pipefail
|
|
|
|
MAX_SIZE=60 # côté max en px (affichées en 20px → net en x3)
|
|
QUALITY=90
|
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
|
ICON_DIR="${1:-$SCRIPT_DIR/test/assets/icons}"
|
|
cd "$ICON_DIR"
|
|
|
|
if command -v magick >/dev/null; then IM=(magick); ID=(magick identify)
|
|
elif command -v convert >/dev/null; then IM=(convert); ID=(identify)
|
|
else echo "ImageMagick introuvable" >&2; exit 1
|
|
fi
|
|
|
|
shopt -s nullglob nocaseglob
|
|
|
|
encode() { "${IM[@]}" "$1" -resize "${MAX_SIZE}x${MAX_SIZE}>" -strip -quality "$QUALITY" "$2"; }
|
|
report() { printf ' %-35s %s %s\n' "$1" "$("${ID[@]}" -format '%wx%h' "$1[0]")" "$(du -h "$1" | cut -f1)"; }
|
|
|
|
converted=0; resized=0; ok=0
|
|
declare -A done_now=()
|
|
|
|
# ── Formats à convertir ────────────────────────────────────────────────
|
|
for src in *.png *.jpg *.jpeg; do
|
|
out="${src%.*}.webp"
|
|
[[ -e "$out" ]] && echo " ⚠️ $out existait, remplacé par la version de $src"
|
|
encode "$src" "$out"
|
|
rm -- "$src"
|
|
report "$out"
|
|
done_now["$out"]=1
|
|
converted=$((converted + 1))
|
|
done
|
|
|
|
# ── WebP existants ─────────────────────────────────────────────────────
|
|
for f in *.webp; do
|
|
[[ -n "${done_now[$f]:-}" ]] && continue
|
|
read -r w h < <("${ID[@]}" -format '%w %h\n' "$f[0]")
|
|
if (( w > MAX_SIZE || h > MAX_SIZE )); then
|
|
encode "$f" "$f.tmp.webp" && mv -- "$f.tmp.webp" "$f"
|
|
report "$f"
|
|
resized=$((resized + 1))
|
|
else
|
|
ok=$((ok + 1))
|
|
fi
|
|
done
|
|
|
|
echo "Converties : $converted | Redimensionnées : $resized | Déjà conformes : $ok"
|