This commit is contained in:
@@ -1,14 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
# Find all files of type PNG, JPEG, or TIFF
|
||||
files=$(find $SCRIPT_DIR/../hugo-content/static/img/ -type f -iname "*.png" -o -iname "*.jpg" -o -iname "*.tif")
|
||||
# Find all files of type PNG, JPEG, TIFF, or HEIC
|
||||
files=$(find "$SCRIPT_DIR/../hugo-content/static/img/" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.tif" -o -iname "*.tiff" -o -iname "*.heic" \))
|
||||
|
||||
# Loop through all the files in the directory
|
||||
for file in $files; do
|
||||
# Convert the file to WEBP
|
||||
cwebp -resize 1500 0 $file -o "${file%.*}.webp"
|
||||
output="${file%.*}.webp"
|
||||
|
||||
# Check if file is HEIC format
|
||||
if [[ "$file" == *.heic ]] || [[ "$file" == *.HEIC ]]; then
|
||||
# Convert HEIC to WebP using sips (built into macOS) and cwebp
|
||||
temp_png="${file%.*}_temp.png"
|
||||
sips -s format png "$file" --out "$temp_png" >/dev/null 2>&1
|
||||
cwebp -resize 1500 0 "$temp_png" -o "$output"
|
||||
rm "$temp_png"
|
||||
else
|
||||
# Convert other formats directly with cwebp
|
||||
cwebp -resize 1500 0 "$file" -o "$output"
|
||||
fi
|
||||
|
||||
# Delete old file
|
||||
rm $file
|
||||
rm "$file"
|
||||
done
|
||||
Reference in New Issue
Block a user