2024-11-02 11:58:45 +07:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-11-11 11:45:12 +07:00
|
|
|
# Check if ImageMagick is installed
|
|
|
|
if ! command -v convert &> /dev/null; then
|
|
|
|
echo "Need ImageMagick as a dependency. Install it with:"
|
|
|
|
echo " sudo apt-get install imagemagick # For GNU/Linux"
|
|
|
|
echo " brew install imagemagick # For macOS"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-11-02 11:58:45 +07:00
|
|
|
# Check if both directory and quality are provided
|
|
|
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
|
|
|
echo "Usage: $0 <directory> <quality>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the directory and quality from arguments
|
|
|
|
directory="$1"
|
|
|
|
quality="$2"
|
|
|
|
|
|
|
|
# Loop through each image in the directory and reduce quality
|
|
|
|
for file in "$directory"/*.{jpg,jpeg,png}; do
|
|
|
|
if [ -f "$file" ]; then
|
|
|
|
convert "$file" -quality "$quality" "$file"
|
|
|
|
echo "Compressed $file to $quality% quality."
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Compression completed for all images in $directory with $quality% quality."
|