Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253#!/bin/bash
# Check if cwebp is installedif ! command -v cwebp &> /dev/null; then echo "cwebp could not be found. Please install it first." exit 1fi
# Function to convert images in a directoryconvert_images() { local dir="$1" # Loop through all image files in the current directory for img in "$dir"/*.jpg "$dir"/*.jpeg "$dir"/*.png "$dir"/*.gif \ "$dir"/*.JPG "$dir"/*.JPEG "$dir"/*.PNG "$dir"/*.GIF; do # Check if there are no image files if [ ! -e "$img" ]; then continue fi
# Define the output file name output="${img%.*}.webp"
# Encode the image to WebP format cwebp "$img" -o "$output"
# Check if the encoding was successful if [ $? -eq 0 ]; then echo "Converted $img to $output" else echo "Failed to convert $img" fi done}
# Function to recursively process directoriesprocess_directory() { local dir="$1" # Convert images in current directory convert_images "$dir" # Process subdirectories for subdir in "$dir"/*/ ; do if [ -d "$subdir" ]; then process_directory "$subdir" fi done}
# Start processing from current directoryprocess_directory "."