Skip to content

Commit

Permalink
Improve how images are optimised
Browse files Browse the repository at this point in the history
  • Loading branch information
ISSOtm committed Dec 21, 2024
1 parent 7ac8d93 commit 8409df6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 20 deletions.
22 changes: 3 additions & 19 deletions optimise_imgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@ set -uo pipefail

git ls-files '*.svg' | xargs -I '{}' svgo --multipass -i'{}'

git ls-files '*.png' '*.jpg' | while read -r file; do
orig=$(wc -c <"$file")
if [[ "$file" = *.jpg ]]; then
convert "$file" "${file%.jpg}.png"
fi
oxipng -Zaso max "${file%.*}.png"
new=$(wc -c <"${file%.*}.png")
printf '%s: %u → %u\n' "$file" "$orig" "$new"
if [[ "$file" = *.jpg ]]; then
if [[ "$new" -lt "$orig" ]]; then
git rm "$file"
git add "${file%.jpg}.png"
else
rm "${file%.jpg}.png"
fi
elif [[ "$new" -gt "$orig" ]]; then
git restore "$file"
fi
done
git ls-files '*.png' | xargs oxipng -Zaso max

git ls-files '*.jpg' '*.jpeg' | xargs jpegoptim --strip-com
Binary file modified static/assets/banner.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified static/assets/improbable_island.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion static/assets/plane.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8409df6

Please sign in to comment.