mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-04 15:03:09 +02:00
feat: added script for comperssing folder
This commit is contained in:
parent
2fb23a9f33
commit
2d6a7815e8
29
compress_images.sh
Normal file
29
compress_images.sh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Directory containing the images
|
||||||
|
directory="./images"
|
||||||
|
|
||||||
|
# Compression level (default to 0 if not provided)
|
||||||
|
compression_level=${1:-0}
|
||||||
|
|
||||||
|
# Create output directory, overwrite if it already exists
|
||||||
|
output_directory="${directory}/webp"
|
||||||
|
rm -rf "$output_directory"
|
||||||
|
mkdir -p "$output_directory"
|
||||||
|
|
||||||
|
# Iterate through each file in the directory
|
||||||
|
for file in "$directory"/*.{jpg,jpeg,png,bmp,tiff}; do
|
||||||
|
# Skip if no matching files are found
|
||||||
|
[ -e "$file" ] || continue
|
||||||
|
|
||||||
|
# Extract the filename without extension
|
||||||
|
filename=$(basename "$file")
|
||||||
|
filename_no_ext="${filename%.*}"
|
||||||
|
|
||||||
|
# Convert the file to WebP with specified compression level
|
||||||
|
cwebp -q "$compression_level" "$file" -o "$output_directory/${filename_no_ext}.webp"
|
||||||
|
|
||||||
|
echo "Converted: $file -> $output_directory/${filename_no_ext}.webp"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "All images have been converted to WebP with compression level $compression_level."
|
||||||
Loading…
Reference in New Issue
Block a user