diff --git a/cabin-4.png b/cabin-4.png deleted file mode 100644 index 6528476..0000000 --- a/cabin-4.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ecaa1057e0764ea574ef559ec71a8b925b79762ce126f78f093d202db26215b8 -size 2330990 diff --git a/car-wreck.png b/car-wreck.png deleted file mode 100644 index 0267f47..0000000 --- a/car-wreck.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:bc209dac7e5276d4c08674c462304009cd25dfde3c6c1e43227ea93a1d7ee568 -size 1017536 diff --git a/city-on-water.jpg b/city-on-water.jpg deleted file mode 100644 index dc49404..0000000 --- a/city-on-water.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8fd40e4cba7bdc706bfbb88c52837e084f7af2c42c63c2b408898573ac435720 -size 1828817 diff --git a/clouds.png b/clouds.png deleted file mode 100644 index eca5dd3..0000000 --- a/clouds.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:894b5e81a7053c989561520c371f61c4a676b945597cd0b5ecfae39f27475dfe -size 3482310 diff --git a/clouds.png.webp b/clouds.png.webp new file mode 100644 index 0000000..4082171 --- /dev/null +++ b/clouds.png.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3edd675a6b04926b3087f1be4ec31ac9d56eb0505cab16d10dff42f4feae80c0 +size 2729466 diff --git a/compare_and_delete_larger.sh b/compare_and_delete_larger.sh new file mode 100755 index 0000000..7ad4e4d --- /dev/null +++ b/compare_and_delete_larger.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Script to compare .png/.jpg with their .webp versions and delete the larger one +# Usage: ./compare_and_delete_larger.sh [directory] +# Default: current directory + +set -euo pipefail + +TARGET_DIR="${1:-.}" + +echo "Scanning for image files in: $TARGET_DIR" + +# Function to process a single image file +process_file() { + local original="$1" + local webp_file="${original}.webp" + + # Check if webp version exists + if [[ ! -f "$webp_file" ]]; then + echo "[SKIP] No webp version for: $original" + return 0 + fi + + # Get file sizes + local original_size + local webp_size + original_size=$(stat -c%s "$original" 2>/dev/null || echo "0") + webp_size=$(stat -c%s "$webp_file" 2>/dev/null || echo "0") + + echo "[COMPARE] $original ($(numfmt --to=iec $original_size)) vs $webp_file ($(numfmt --to=iec $webp_size))" + + # Compare sizes + if [[ "$original_size" -gt "$webp_size" ]]; then + echo "[DELETE] $original is larger, deleting..." + rm -v "$original" + elif [[ "$original_size" -lt "$webp_size" ]]; then + echo "[DELETE] $webp_file is larger, deleting..." + rm -v "$webp_file" + else + echo "[SKIP] Both files have the same size" + fi +} + +# Export the function for use with find -exec +Export_func() { + export -f process_file +} +Export_func + +# Find all .png and .jpg files (case insensitive) and process them +find "$TARGET_DIR" -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" \) -print0 | while IFS= read -r -d '' file; do + process_file "$file" +done + +echo "" +echo "Done!" diff --git a/convert_to_webp.sh b/convert_to_webp.sh new file mode 100755 index 0000000..b32cbbc --- /dev/null +++ b/convert_to_webp.sh @@ -0,0 +1,119 @@ +#!/bin/bash + +# Batch convert all PNG/JPG/JPEG to WebP +# Usage: ./convert_to_webp.sh +# Output: appends .webp to each filename (e.g., "file.png" -> "file.png.webp") +# This avoids filename collisions - you can clean up names later + +set -e + +echo "=== WebP Batch Conversion ===" +echo "Starting at: $(date)" +echo "" + +TOTAL_ORIGINAL=0 +TOTAL_WEBP=0 +CONVERTED=0 +SKIPPED=0 + +# Function to format bytes +format_bytes() { + local bytes=$1 + if (( bytes >= 1073741824 )); then + echo "$(echo "scale=2; $bytes / 1073741824" | bc) GB" + elif (( bytes >= 1048576 )); then + echo "$(echo "scale=2; $bytes / 1048576" | bc) MB" + elif (( bytes >= 1024 )); then + echo "$(echo "scale=2; $bytes / 1024" | bc) KB" + else + echo "$bytes B" + fi +} + +echo "Processing PNG files (lossless)..." +for f in *.png; do + [ -f "$f" ] || continue + + original_size=$(stat -c%s "$f") + TOTAL_ORIGINAL=$((TOTAL_ORIGINAL + original_size)) + + output="${f}.webp" + + # Skip if already converted + if [ -f "$output" ]; then + echo " SKIP (already exists): $f" + SKIPPED=$((SKIPPED + 1)) + continue + fi + + echo -n " Converting: $f ... " + cwebp -lossless "$f" -o "$output" > /dev/null 2>&1 + + if [ -f "$output" ] && [ -s "$output" ]; then + webp_size=$(stat -c%s "$output") + TOTAL_WEBP=$((TOTAL_WEBP + webp_size)) + savings=$((original_size - webp_size)) + pct=$(echo "scale=1; $savings * 100 / $original_size" | bc) + echo "DONE [$(format_bytes $original_size) -> $(format_bytes $webp_size) | ${pct}% saved]" + CONVERTED=$((CONVERTED + 1)) + else + echo "FAILED" + fi +done + +echo "" +echo "Processing JPG/JPEG files (quality 100)..." +for f in *.jpg *.jpeg; do + [ -f "$f" ] || continue + + original_size=$(stat -c%s "$f") + TOTAL_ORIGINAL=$((TOTAL_ORIGINAL + original_size)) + + output="${f}.webp" + + # Skip if already converted + if [ -f "$output" ]; then + echo " SKIP (already exists): $f" + SKIPPED=$((SKIPPED + 1)) + continue + fi + + echo -n " Converting: $f ... " + cwebp -q 100 "$f" -o "$output" > /dev/null 2>&1 + + if [ -f "$output" ] && [ -s "$output" ]; then + webp_size=$(stat -c%s "$output") + TOTAL_WEBP=$((TOTAL_WEBP + webp_size)) + savings=$((original_size - webp_size)) + pct=$(echo "scale=1; $savings * 100 / $original_size" | bc) + echo "DONE [$(format_bytes $original_size) -> $(format_bytes $webp_size) | ${pct}% saved]" + CONVERTED=$((CONVERTED + 1)) + else + echo "FAILED" + fi +done + +echo "" +echo "=== Summary ===" +echo "Converted: $CONVERTED files" +echo "Skipped: $SKIPPED files (already exist)" +echo "" +echo "Original total: $(format_bytes $TOTAL_ORIGINAL)" +echo "WebP total: $(format_bytes $TOTAL_WEBP)" + +if [ $TOTAL_ORIGINAL -gt 0 ]; then + SAVINGS=$((TOTAL_ORIGINAL - TOTAL_WEBP)) + PCT=$(echo "scale=1; $SAVINGS * 100 / $TOTAL_ORIGINAL" | bc) + echo "Space saved: $(format_bytes $SAVINGS) ($PCT%)" +fi + +echo "" +echo "Finished at: $(date)" +echo "" +echo "=== Git LFS Note ===" +echo "The .webp files are NOT added to git." +echo "To track them with Git LFS later, run:" +echo " git lfs track '*.webp'" +echo " git add .gitattributes" +echo " git add *.webp" +echo " git commit -m 'Add WebP versions'" diff --git a/cool.jpg b/cool.jpg deleted file mode 100644 index dcda464..0000000 --- a/cool.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b639728cf45323fadfb2b961e520661750f1cc76f4bb1430b8f87b4dd5f7e4c7 -size 1568898 diff --git a/corals-fish-underwater.jpg b/corals-fish-underwater.jpg deleted file mode 100644 index 31fd61d..0000000 --- a/corals-fish-underwater.jpg +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:10b645692d0f8c30747ee8e9c63edee5a7b878fc633dfb736cb3970786f69e3d -size 4148793