Created
August 5, 2026 05:28
-
-
Save zoxon/897ec364bad74eb2d12b1f2af300d4eb to your computer and use it in GitHub Desktop.
Convert images for web
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Check if sharp-cli is installed | |
| if ! command -v sharp &> /dev/null; then | |
| echo "Error: sharp-cli is not installed. Please install it using 'npm install -g sharp-cli'." | |
| exit 1 | |
| fi | |
| # Directories | |
| INPUT_DIR="." | |
| OUTPUT_DIR="./output" | |
| # Create output folders | |
| mkdir -p "$OUTPUT_DIR" | |
| # PNG lossless | |
| sharp -i "$INPUT_DIR/*.png" -o "$OUTPUT_DIR" \ | |
| --format png --lossless --effort 6 | |
| # JPEG remove artifacts | |
| sharp -i "$INPUT_DIR/*.{jpg,jpeg}" -o "$OUTPUT_DIR" \ | |
| --format jpeg \ | |
| --quality 90 \ | |
| --trellisQuantisation \ | |
| --chromaSubsampling 4:4:4 \ | |
| --progressive | |
| # JPEG -> AVIF + WEBP | |
| sharp -i "$OUTPUT_DIR/*.{jpg,jpeg}" -o "$OUTPUT_DIR" \ | |
| --format avif --quality 75 --effort 6 --chromaSubsampling 4:4:4 | |
| sharp -i "$OUTPUT_DIR/*.{jpg,jpeg}" -o "$OUTPUT_DIR" \ | |
| --format webp --quality 80 --smartSubsample --nearLossless=70 | |
| # PNG → AVIF + WebP | |
| sharp -i "$INPUT_DIR/*.png" -o "$OUTPUT_DIR" \ | |
| --format avif --quality 75 --effort 6 --chromaSubsampling 4:4:4 | |
| sharp -i "$INPUT_DIR/*.png" -o "$OUTPUT_DIR" \ | |
| --format webp --quality 80 --smartSubsample | |
| echo "✓ All images processed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment