Converting images to WebP using coding agents

By Pradyumna Chippigiri

January 18, 2026


When i am ship my blog pages, i try and convert my pngs/jpegs to WebP as it can cut transfer size drastically. I now let coding agents batch-convert PNG/JPG assets and update references automatically. I just give a prompt like this to cursor/codex: (you can change it accordingly)(just for context)

Convert all PNG images used in page.mdx to WebP. Save them under 
public/images/ 
update the MDX references to .webp, and remove the old PNGs after verifying the new images load

Internally it runs this command :

for f in public/images/**/*.png; do cwebp -q 80 "$f" -o "${f%.png}.webp"; done

Meaning (piece by piece):

cwebp does the real work. It re-encodes PNG data into WebP, which is what usually reduces file size.

If you use lossy WebP (-q 80 like above), you may see a tiny quality drop. If you want no quality loss, then u can tell that to the agent it will do it for you, but internally it does something like this:

cwebp -lossless input.png -o output.webp

Lossless keeps quality intact, but file sizes may be larger than lossy.

Why it helps