summaryrefslogtreecommitdiffstats
path: root/indieweb-micro/prep-images.sh
blob: e4783488fc89bb54d81c7bfd7aa91835aafeb769 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash

# Usage:
#   ./overwrite-to-webp.sh /path/to/folder jpg
#
# Arguments:
#   1 = folder containing images
#   2 = file extension to convert (jpg, jpeg, png, etc.)

SRC_DIR="$1"
EXT="$2"

if [ -z "$SRC_DIR" ] || [ -z "$EXT" ]; then
    echo "Usage: $0 <folder> <extension>"
    echo "Example: ./overwrite-to-webp.sh ./photos jpg"
    exit 1
fi

for file in "$SRC_DIR"/*."$EXT"; do
    [ -e "$file" ] || continue

    filename=$(basename "$file")
    name="${filename%.*}"
    newfile="$SRC_DIR/$name.webp"

    echo "Converting: $filename → $name.webp"

    # Convert to WebP (lossy quality ~80)
    ffmpeg -i "$file" \
        -compression_level 6 \
        -quality 80 \
        "$newfile" -y

    # Delete original file
    rm -f "$file"
done

echo "Done! All .$EXT files have been replaced with .webp"
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage