Back to rankings

ascorbic/unpic-img

TypeScriptunpic.pics

Multi-framework responsive image component

imagesreactvueastropreactqwiksolidjssveltewebclitangular
Star Growth
Stars
2.1k
Forks
67
Weekly Growth
Issues
35
1k1.5k2k
Feb 2023Mar 2024May 2025Jul 2026
Artifactsnpmnpm install unpic-img
README

🌳 unpic-img

A cross-framework component for responsive, high-performance images using image CDNs

react Reactvue Vuesolidjs SolidJSsvelte Svelteastro Astro

preact Preactqwik Qwikwebc WebCangular Angularlit Lit

Features

  • Just an <img> tag! No extra elements, no runtime JavaScript. Easy to style. No legacy hacks or workarounds.
  • Automatically generates correct srcset and sizes attributes for responsive images.
  • Handles responsive resizing of images, preserving aspect ratio and avoiding layout shift.
  • Uses native lazy loading and async decoding for offscreen images.
  • Handles different image layouts: fixed, constrained and full width.
  • Uses eager loading and high priority fetching for important images.
  • Delivers modern image formats, including WebP and AVIF if supported by the browser.
  • No build step or server-side rendering required for the images: uses your existing image CDN or CMS, with no additional configuration.
  • Uses unpic lib to support most image CDNs, including Cloudinary, Imgix, and Shopify.
  • Can generate a low-res background image for a blurred placeholder effect, or use with @unpic/placeholder for more options.

Usage

For details of usage, see the documentation.

FAQ

Why do I need this?

While it's easy to use an <img> tag for images, if you want to follow best practices and deliver the most performant image to your users then it can take a lot of work. Some frontend frameworks will automate this for you, but they often rely on slow pre-rendering of images, or on running image optimizers on your own site. They also generate complex HTML with wrappers and spacer elements that make images hard to style.

Most images on modern websites are hosted on a CDN or CMS that can resize images on the fly and deliver them at the edge. Despite this, most web frameworks will still download and resize the image at build time or on your server, rather than using the CDN, or just uses a single source image rather than handling multiple resolutions.

This library works with any frontend framework or none, and uses your existing image CDN or CMS, with no additional configuration.

For more details, see this post.

How does this work?

This library uses unpic to detect the image CDN, and then uses the CDN's URL API to resize and format images. It then generates the correct srcset and sizes attributes for the image. It uses new features built into modern browsers to handle lazy loading, fetch priority and decoding. It also uses pure CSS to handle responsive resizing of images, preserving aspect ratio and avoiding layout shift. Unlike most other image components, it does not use any client-side JavaScript by default, and generates just a single <img> tag without any wrapper divs or padding elements.

What HTML does this generate?

Generated HTML for a constrained image It turns this:
<Image
  src="https://cdn.shopify.com/static/sample-images/bath_grande_crop_center.jpeg"
  layout="constrained"
  width={800}
  height={600}
  alt="Shopify"
/>

...into this:

<img
  alt="Shopify"
  loading="lazy"
  decoding="async"
  sizes="(min-width: 800px) 800px, 100vw"
  srcset="
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=1600&amp;height=2133 1600w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=1280&amp;height=1707 1280w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=1080&amp;height=1440 1080w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=960&amp;height=1280   960w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=828&amp;height=1104   828w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=800&amp;height=1067   800w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=750&amp;height=1000   750w,
    https://cdn.shopify.com/static/sample-images/bath.jpeg?crop=center&amp;width=640&amp;height=853    640w
  "
  src="https://cdn.shopify.com/static/sample-images/bath.jpeg?width=800&amp;height=600&amp;crop=center"
  style="
        object-fit: cover;
        max-width: 800px;
        max-height: 600px;
        aspect-ratio: 1.33333 / 1;
        width: 100%;
      "
/>

Supported CDNs

You can use any image CDN supported by unpic lib, including:

  • Adobe Dynamic Media (Scene7)
  • Builder.io
  • Bunny.net
  • Cloudflare
  • Contentful
  • Cloudinary
  • Directus
  • Imgix, including Unsplash, DatoCMS, Sanity and Prismic
  • Kontent.ai
  • Netlify
  • Shopify
  • Storyblok
  • Vercel / Next.js
  • WordPress.com and Jetpack Site Accelerator

License

Published under the MIT licence. © Matt Kane 2023.

Related repositories
ssloy/tinyrenderer

A brief computer graphics / rendering course

C++Otheropenglc-plus-plus
haqr.eu/tinyrenderer/
23.9k2.3k
aleju/imgaug

Image augmentation for machine learning experiments.

PythonPyPIMIT Licenseimage-augmentationmachine-learning
imgaug.readthedocs.io
14.7k2.5k
LuckSiege/PictureSelector

Picture Selector Library for Android or 图片选择器

JavaMavenApache License 2.0androidandroid-image-selector
13.6k3.1k
coil-kt/coil

Image loading for Android and Compose Multiplatform.

KotlinApache License 2.0androidkotlin
coil-kt.github.io/coil/
11.9k774
verlok/vanilla-lazyload

LazyLoad is a lightweight, flexible script that speeds up your website by deferring the loading of your below-the-fold images, backgrounds, videos, iframes and scripts to when they will enter the viewport. Written in plain "vanilla" JavaScript, it leverages IntersectionObserver, supports responsive images and enables native lazy loading.

JavaScriptnpmMIT Licenselazyload-imageslazy-loading
andreaverlicchi.eu/vanilla-lazyload/
7.9k673
ApoorvSaxena/lozad.js

🔥 Highly performant, light ~1kb and configurable lazy loader in pure JS with no dependencies for responsive images, iframes and more

JavaScriptnpmMIT Licenseperformancejavascript
apoorv.pro/lozad.js/demo/
7.5k436
axa-group/Parsr

Transforms PDF, Documents and Images into Enriched Structured Data

JavaScriptnpmApache License 2.0parsrpdf
6.2k323
spatie/laravel-medialibrary

Associate files with Eloquent models

PHPPackagistMIT Licenselaravelphp
spatie.be/docs/laravel-medialibrary
6.2k1.1k
mifi/editly

Slick, declarative command line video editing & API

TypeScriptnpmMIT Licensevideo-editoropengl
5.5k371
ssloy/tinyraytracer

A brief computer graphics / rendering course

C++c-plus-plusgraphics
github.com/ssloy/tinyraytracer/wiki
5.3k351
hpjansson/chafa

📺🗿 Terminal graphics for the 21st century.

CGNU Lesser General Public License v3.0ansiterminal-graphics
hpjansson.org/chafa/
5k114
lsky-org/lsky-pro

☁️兰空图床(Lsky Pro) - Your photo album on the cloud.

BladeGNU General Public License v3.0mduiimages
lsky.pro
4.7k672