Created
June 25, 2024 14:43
-
-
Save emmadesilva/cbbc88806223b6cec3d77239fc395e20 to your computer and use it in GitHub Desktop.
Bash ImageMagick script to compress images in a directory named source to a directory called output
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 | |
| # Ensure the output directory exists | |
| mkdir -p output | |
| # Iterate through all image files in the source directory | |
| for image in source/*.{jpg,jpeg,png,gif}; do | |
| if [[ -f "$image" ]]; then | |
| # Get the filename without the directory path | |
| filename=$(basename "$image") | |
| # Print output | |
| echo "converting $filename" | |
| # Compress the image and save it to the output directory | |
| convert "$image" -strip -interlace Plane -gaussian-blur 0.05 -quality 85% "output/$filename" | |
| fi | |
| done | |
| echo "Image compression complete. Compressed images are saved in the 'output' directory." |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Video version