-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimizeimages.sh
More file actions
executable file
·33 lines (28 loc) · 1014 Bytes
/
optimizeimages.sh
File metadata and controls
executable file
·33 lines (28 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
set -euo pipefail
SRC="img/promo"
DST="img/promo/preview"
# Prefer ImageMagick 7's `magick` if present, otherwise fall back to the v6
# `convert` binary. `convert` is what ships on Ubuntu (apt) and is also
# available on macOS Homebrew v7 installs as a back-compat alias.
if command -v magick >/dev/null 2>&1; then
IM=(magick)
elif command -v convert >/dev/null 2>&1; then
IM=(convert)
else
echo "error: ImageMagick not found. Install via 'brew install imagemagick' (macOS) or 'sudo apt-get install imagemagick' (Debian/Ubuntu)." >&2
exit 1
fi
mkdir -p "$DST"
for f in "$SRC"/*.png; do
[ -e "$f" ] || continue
out="$DST/$(basename "$f")"
"${IM[@]}" "$f" \
-resize '1200x630>' \
-define png:compression-level=9 \
-define png:compression-filter=5 \
-define png:compression-strategy=1 \
"$out"
printf " %-40s %8d -> %8d bytes\n" "$(basename "$f")" "$(wc -c <"$f")" "$(wc -c <"$out")"
done
echo "done. wrote $(ls "$DST" | wc -l | tr -d ' ') files to $DST"