mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 19:43:11 +02:00
git-subtree-dir: linux_configuration git-subtree-mainline:11427631cdgit-subtree-split:0762e3d07b
30 lines
895 B
Bash
30 lines
895 B
Bash
#!/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."
|