img2webp for Quick Image Conversion - 2024-01-26
Whenever I post an image online, I try to reduce the size by converting it to webp.
To speed up this process, I wrote a one-liner using ffmpeg:
$ which img2webp
img2webp () {
ffmpeg -hide_banner -loglevel error -i $1 -c:v libwebp ${1/\.*/\.webp} >> /dev/null
ls -lah $1
ls -lah ${1/\.*/\.webp}
}
Let’s see it in use:
$ img2webp IMG_2228.jpeg
-rw-r--r--@ 1 maltekrupa staff 2.4M Jan 26 08:15 IMG_2228.jpeg
-rw-r--r-- 1 maltekrupa staff 570K Jan 26 08:16 IMG_2228.webp
It usually takes less than a second on a three year old M1 Mac and since ffmpeg is such an amazing tool, it works with basically any image format.