Convert images to WebP recursively
bulk convert jpg to webp linux | convert all images to webp command line | generate webp for wordpress uploads | cwebp recursive conversion | cwebp | webp | images | findCaution: This command changes the system. Understand what it does before you run it.
find /var/www/vhosts/example.com/httpdocs/wp-content/uploads -type f \( -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.png' \) -exec sh -c 'for f; do [ -e "$f.webp" ] || cwebp -quiet -q 80 "$f" -o "$f.webp"; done' sh {} +Converts each JPEG and PNG to WebP and saves the result as bild.jpg.webp next to the original. Existing WebP files are skipped, so running it again only processes new images. WebP is usually much smaller than JPEG, which improves load time and LCP.
Note: cwebp is part of the webp package. The web server or a plugin has to take care of serving the files. When run as root, the new files belong to root, so better run it as the webspace user.
Also searched as
- bulk convert jpg to webp linux
- convert all images to webp command line
- generate webp for wordpress uploads
- cwebp recursive conversion