I wanted to reduce the file size of my image assets. At this point in time I'm not serving many images, but I wanted to ensure the web performance is as best it can be. I decided to go down the route of storing the webP image format assets in an AWS S3 Bucket1 and deliver those with AWS Cloudfront2.
With a little help from Claude, I created a Python script that converts SUPPORTED_FORMATS = {'.jpg', '.jpeg', '.png', '.bmp', '.tiff'}
into webP format3.
Firstly, I setup a folder webp-converter
this housed the Python script. I then created the following folder images-to-convert
, this contains all my original image assets ready to be converted.
Inside the directory webp-converter
using the folllowing command python3 webp-converter.py
runs the script to convert images into the webP image format. The images are then stored in the webp_converted
folder ready for S3.
Once I was happy the script worked, I then asked Claude to add detailed comments:
WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web faster.