Show HN: ViewFit – Resize images to the size they are rendered at github.com · 2...
Show HN @show
Show HN: ViewFit – Resize images to the size they are rendered at github.com · 2 points · 0 comments · HN thread
TL;DR ViewFit is a command-line tool that opens a built website in headless Chromium, measures how large each image is actually rendered, and resizes and compresses each file to that size using Sharp. The README reports a demo page dropping from 12.0 MB to 893 KB. The Show HN post had 2 points and no comments at the time of capture.
- Measures each and CSS background-image with getBoundingClientRect() in Chromium, applies the device pixel ratio, and recommends a per-image target size.
- Commands: viewfit or viewfit inspect for a report-only run, and viewfit optimize to write resized copies, optionally with --site to rewrite HTML/CSS/JS references.
- Presets: web (mobile, WebP, 90% tier, quality 80), hq (desktop, AVIF, 100%, quality 85), fast (mobile, WebP, 75%, quality 70).
- Tiers scale the exact rendered size: exact 100%, safe 90%, aggressive 75%, extreme 50%, or any custom percentage.
- Demo: a two-page example with six large Unsplash photos and a 24 MB PNG icon went from 12.0 MB to 893 KB, with one card image going from 3902×5050 JPG to 733×949 WebP.
- Remote or CDN images are reported but not modified; directory targets compress each unique image once using the largest rendered size found across pages.
- Requires Node.js 18 or later and a Chromium install for Playwright (or Google Chrome via --browser chrome); MIT licensed.
Discussion No comments have been posted yet, so there is no discussion to summarize.
#images #cli #webPerformance #nodejs #playwright #imageCompression