Last active
December 10, 2025 02:36
-
-
Save bearlikelion/f6c0cba8bdd9bacbebd212bc571c3cee to your computer and use it in GitHub Desktop.
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 | |
| # Script to convert all JPG files to 90% compression and resize to 1024x1024 | |
| # WARNING: This will OVERWRITE original files! | |
| # Recursively processes all subdirectories | |
| # Usage: ./convert_images.sh [directory] | |
| # If no directory is specified, uses current directory | |
| # Set the target directory (default to current directory if not provided) | |
| TARGET_DIR="${1:-.}" | |
| # Check if ImageMagick is installed | |
| if ! command -v mogrify &> /dev/null; then | |
| echo "Error: ImageMagick is not installed. Please install it first." | |
| echo "On Ubuntu/Debian: sudo apt-get install imagemagick" | |
| echo "On Arch/CachyOS: sudo pacman -S imagemagick" | |
| exit 1 | |
| fi | |
| # Counter for processed files | |
| count=0 | |
| echo "WARNING: This will overwrite original files!" | |
| echo "Processing JPG files recursively in: $TARGET_DIR" | |
| echo "" | |
| # Find and process all JPG files recursively (case insensitive) | |
| find "$TARGET_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" \) | while read -r file; do | |
| echo "Processing: $file" | |
| # Convert image: resize to 1024x1024 and compress to 90% quality | |
| # Using mogrify to overwrite the original file | |
| mogrify -resize 1024x1024 -quality 90 "$file" | |
| if [ $? -eq 0 ]; then | |
| echo " ✓ Converted successfully" | |
| ((count++)) | |
| else | |
| echo " ✗ Failed to convert" | |
| fi | |
| done | |
| echo "" | |
| echo "Conversion complete!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment