- May 17, 2013
- 3,970
- 24,169
In this short tutorial, I will show how to convert&optimize your images into WebP, save hosting space and increase your WordPress site's performance. Let's say you want to bulk convert 50GB of images.
NOTE 1: This is an integral part of the site speed optimization, but it doesn't cover the entire performance optimization process. You have to ensure your entire site is optimized (scripts, etc.) and use quality hosting. As usual, I recommend using NVMe as the best option.
What is WebP?
WebP is the most used image format nowadays for speed improvements. Google developed it in 2010. It provides a smaller size and better quality than other popular formats such as JPEG, PNG, and GIF.
The WebP format uses lossy and lossless compression to achieve higher compression ratios than JPEG or PNG images of the same quality setting and resolution.
Note 2: Do a backup of your site's files in case of any issue.
Solution I - Do it the Coyote style, make that fish swim faster.
Download and install Google's WebP Converter command-line tool and create a .bat file using the following code:
Code:
@Echo off
for %%f in (*.png) do cwebp -q 74 %%~nf.png -o %%~nf.webp
del *.png
for %%f in (*.jpg) do cwebp -q 74 %%~nf.jpg -o %%~nf.webp
del *.jpg
for %%f in (*.jpeg) do cwebp -q 74 %%~nf.jpeg -o %%~nf.webp
del *.jpeg
Insert the .bat file in a folder with png, jpg, or jpeg files, and it will convert them all.
Attention: This script deletes the original file! Make sure you saved a copy of the media folder in another place!
Solution II - Here is how to do it faster than a running Coyote, not even a bunny could get away:
If you cannot install Google's WebP converter on your hosting, you have to rent a VPS for a few days.
- Rent a quality VPS (DO/Hetzner/Interserver/Vultr). For a 50GB size, you need to rent around 100GB-150GB VPS server (temporary files, buffer, etc.).
- Go on Google and search for: "convert the PNG and JPEG images to the ".webp" format using the command-line utility of WebP" (you will find a ton of cwebp command-line utility's tuts).
- Install the required codec.
- Upload the images folder of your WordPress site on the VPS.
- Run the batch process. It will take some time to convert, depending on the size number of the images and the VPS power.
- Download the folder from the VPS and re-upload it to the original location (your WordPress site) or, even better, on your CDN.