Skip to content

Instantly share code, notes, and snippets.

@Antosik
Created July 1, 2024 13:32
Show Gist options
  • Save Antosik/8a6c881adbd81cbdecc0e300b9d7c90c to your computer and use it in GitHub Desktop.
Save Antosik/8a6c881adbd81cbdecc0e300b9d7c90c to your computer and use it in GitHub Desktop.
Image optimizer (OxiPNG, WebP, AVIF)
PNG_IMAGES := $(wildcard ./src/*/*.png ./src/*/*/*.png ./static/*/*.png ./static/*/*/*.png)
JPG_IMAGES := $(wildcard ./src/*/*.jpg ./src/*/*/*.jpg ./static/*/*.jpg ./static/*/*/*.jpg)
optimize-images: optimize-svg optimize-png optimize-avif optimize-webp
optimize-svg:
npx svgo --multipass -f ./src -r && \
npx svgo --multipass -f ./static -r
optimize-png:
brew install oxipng && \
oxipng -o 2 --strip safe $(PNG_IMAGES)
optimize-avif:
npx avif --lossless --overwrite --input="./src/**/**/*.{png,jpg}" && \
npx avif --lossless --overwrite --input="./static/**/**/*.{png,jpg}"
optimize-webp:
brew install webp
$(foreach file, $(PNG_IMAGES), cwebp -mt -lossless $(file) -o $(file:.png=.webp);)
$(foreach file, $(JPG_IMAGES), cwebp -mt -lossless $(file) -o $(file:.jpg=.webp);)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment