1sudo apt update
2sudo apt install webp
1cwebp -q 100 sample_image.png -o sample_image.webp
1# convert all jpeg files in a folder
2for F in *.jpg; do cwebp $F -o `basename ${F%.jpg}`.webp; done
3
4# Convert all files in a directory
5for file in images/*; do cwebp "$file" -o "${file%.*}.webp"; done
<picture>
tagBefore:
1<img src="flower.jpg" alt="" />
After:
1<!-- order of listing matters in source tag. top will be tried first -->
2<picture>
3 <source type="image/webp" srcset="flower.webp" />
4 <source type="image/jpeg" srcset="flower.jpg" />
5 <!-- img tag should always be included, and it should always be last -->
6 <img src="flower.jpg" alt="" />
7</picture>
mod_rewrite
, and take care of it on a server level. No need to add <picture>
elements inside existing code<picture>
, the browser uses the first listed source that’s in a format it supports. If the browser does not support any of the formats listed in the <source>
tags, it falls back to loading the image specified by the <img>
tag.