Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ea30e5b authored by minaripenguin's avatar minaripenguin Committed by Mohammed Althaf T
Browse files

Add script for webp conversion



Change-Id: Ifbf79c132ed348ea29e1945d8d44d74caef4a344
Signed-off-by: default avatarminaripenguin <minaripenguin@users.noreply.github.com>
Signed-off-by: default avataralthafvly <althafvly@gmail.com>
parent e6a4f371
Loading
Loading
Loading
Loading

convert2webp.sh

0 → 100755
+56 −0
Original line number Diff line number Diff line
#!/bin/bash

# Check if required commands are installed
for cmd in parallel cwebp; do
    if ! command -v "$cmd" &> /dev/null; then
        echo "$cmd is not installed. Please install it with:"
        case "$cmd" in
            parallel)
                echo "  sudo apt install parallel      # Debian/Ubuntu"
                echo "  sudo pacman -S parallel        # Arch"
                echo "  brew install parallel          # macOS"
                ;;
            cwebp)
                echo "  sudo apt install webp          # Debian/Ubuntu"
                echo "  sudo pacman -S libwebp         # Arch"
                echo "  brew install webp              # macOS"
                ;;
        esac
        exit 1
    fi
done

TARGET_DIRS=(
    "./res_phone/drawable-nodpi"
    "./res_tablet/drawable-nodpi"
)

SUPPORTED_EXTENSIONS="png jpg jpeg"

for TARGET_DIR in "${TARGET_DIRS[@]}"; do
    if [ ! -d "$TARGET_DIR" ]; then
        echo "Directory $TARGET_DIR does not exist. Skipping..."
        continue
    fi

    FILES=()
    for ext in $SUPPORTED_EXTENSIONS; do
        while IFS= read -r -d '' file; do
            FILES+=("$file")
        done < <(find "$TARGET_DIR" -maxdepth 1 -type f -iname "*.$ext" -print0)
    done

    if [ ${#FILES[@]} -eq 0 ]; then
        echo "No supported image files found in $TARGET_DIR."
        continue
    fi

    echo "Converting images in $TARGET_DIR to lossless WEBP format..."
    printf "%s\0" "${FILES[@]}" | parallel -0 -eta 'cwebp -q 100 {} -o {.}.webp && rm "{}"'

    if [ $? -eq 0 ]; then
        echo "Conversion completed in $TARGET_DIR. Non-WEBP files deleted."
    else
        echo "An error occurred during conversion in $TARGET_DIR."
    fi
done