Created
January 2, 2026 16:33
-
-
Save corbtastik/22017eb6221c0398640b05c2ffb9b25d to your computer and use it in GitHub Desktop.
Blog Image Optimizer script
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 | |
| # 1. Define the target width for your blog (e.g., 1600px) | |
| WIDTH=1600 | |
| # 2. Loop through all HEIC files (case-insensitive) | |
| for file in *.[hH][eE][iI][cC]; do | |
| # Check if files actually exist to avoid errors | |
| [ -e "$file" ] || continue | |
| # 3. Create a clean filename (e.g., IMG_123.jpg) | |
| filename="${file%.*}" | |
| output_name="${filename}.jpg" | |
| echo "Processing $file..." | |
| # 4. Convert and Resize using 'sips' | |
| # -s format: sets output to jpeg | |
| # -Z: maintains aspect ratio and sets max dimension | |
| sips -s format jpeg -Z $WIDTH "$file" --out "$output_name" | |
| echo "Created $output_name" | |
| done | |
| echo "Done! Your web-ready images are ready." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment