Developer shrinks 1.1 GB AI image gallery to 30 MB using WebP conversion trick
A developer running a small AI photo-prompt gallery discovered that 1,541 PNG files were consuming 892 MB — about 75% of total storage — simply because the image generator exported lossless PNGs by default instead of a web-friendly format. Converting all images to WebP at quality 82 reduced the total size from 423.7 MB to just 29.8 MB, a 93% reduction, without any visible loss in image quality. Rather than overwriting originals or updating database URLs, the developer generated sibling WebP files and served them via HTML's picture element, ensuring automatic fallback for unsupported browsers and easy rollback. A surprising bug during the process caused images to be double-wrapped in picture tags due to a shortcode running through two content filters, which was fixed by stamping a data attribute on already-processed tags. The project highlighted that format choice, not image dimensions or compression levels, was the primary cause of bloat.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in