Created
March 18, 2026 00:08
-
-
Save schappim/b773ca97b2aebc0ea5daec242b0fb84b to your computer and use it in GitHub Desktop.
convert_to_webp.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alias webpconvert='convert_to_webp' | |
| convert_to_webp() { | |
| original_path="$1" | |
| output_path="${original_path%.*}.webp" | |
| extension="${original_path##*.}" | |
| extension_lower=$(echo "$extension" | tr '[:upper:]' '[:lower:]') | |
| if [[ "$extension_lower" == "heic" || "$extension_lower" == "heif" ]]; then | |
| # Convert HEIC/HEIF to temporary JPEG first, then to WebP | |
| temp_file=$(mktemp /tmp/webp_convert.XXXXXX.jpg) | |
| sips -s format jpeg "$original_path" --out "$temp_file" >/dev/null 2>&1 | |
| cwebp -q 70 "$temp_file" -o "$output_path" | |
| rm "$temp_file" | |
| else | |
| cwebp -q 70 "$original_path" -o "$output_path" | |
| fi | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment