To Webp Functions
To Webp
A simple for loop to make using globs easier with cwebp.
function towebp -d "Convert image files to web with cweb"
for SOURCE_IMAGE in $argv
set OUTPUT (path change-extension webp $SOURCE_IMAGE)
cwebp $SOURCE_IMAGE -o $OUTPUT
end
end
I'm pretty sure I saw a one-liner to do this (using pipes) but it was hard to understand so I thought this would make it clearer to myself what is going on, rather than just copying a command I can't figure out.
Lossless Webp
The previous function used the default compression (lossy). This uses the lossless conversion with maximum compression and quality.
I looked in the source code (from Google's libwebp
git repository) and the -z
flag is equivalent to using -lossless -m 6 -q 10
(or whatever the max is for both of them), although for some reason it seemed to do better when I was testing it earlier…
function losslesswebp --description 'Convert image files to lossless webp'
for SOURCE_IMAGE in $argv
set OUTPUT (path change-extension .z9.webp $SOURCE_IMAGE)
cwebp -z 9 $SOURCE_IMAGE -o $OUTPUT
end
end