Scale images with sharp

With the sharp library, you can build an image component and converter in userland. The images below are cropped, resized and converted to AVIF or WebP on the fly, depending on what your browser accepts. The image converter is also used in the products example.

Each image starts as a blurred placeholder: a 24 pixel version, inlined into the HTML as data: URI of a few hundred bytes. It shows up instantly and keeps the layout stable, until the full image has loaded and covers it. No JavaScript is involved.

Crop strategyalways cut out the middle
Placeholders only

The originals are landscape photos, cut to portraits. The frame on each original shows which part sharp keeps.