imgix-srcset
v1.1.0
Published
A dead simple utility to generate responsive srcsets from an Imgix compatible source URL
Downloads
2
Readme
Imgix SrSet Generator
A dead simple utility to generate responsive srcsets from an Imgix compatible source URL
Usage
Install via npm (or yarn etc)
npm i imgix-srcset
Import into your project and generate a srcset for any image you need, from an Imgix compatbile URL
Plain JS
import { srcset } from 'imgix-srcset';
const img = document.createElement('img');
img.src = '...';
img.srcset = srcset('...');
React
import { srcset } from 'imgix-srcset';
function ReactLazyImgix({ src }) {
return <img src={src} srcset={srcset(src)} loading="lazy" />;
}
Imgix Options
By default existing parameters are stripped from the src Imgix image, you can specify any Imgix propreties you want in the srcset
function
srcset('...', {
fit: 'crop',
ar: '16:9'
});