This package has been deprecated

Author message:

Package no longer supported. Use @renditions/get-sizes instead.

@renditions/get-img-sizes

0.0.5 • Public • Published

@renditions/get-img-sizes

npm version js-standard-style

Generate string for HTML image sizes attribute.

Install

npm install @renditions/get-img-sizes

Usage

import getImgSizes from '@renditions/get-img-sizes'

const sizes = getImgSizes({
  defaultImageWidth: '100vw',
  breakpoints: [
    {
      viewportMinWidth: '960px',
      imageWidth: '50vw'
    },
    {
      viewportMinWidth: '480px'
    }
  ]
})

console.log(sizes)

The above code logs the following string to the console:

(min-width: 960px) 50vw,(min-width: 480px) 100vw,100vw

Using with React

import React from 'react'
import getSizes from '@renditions/get-img-sizes'

const Image = ({ width, ...rest }) => {
  const sizes = getSizes({ defaultImageWidth: width })

  return <img sizes={sizes} {...rest} />
}

Package Sidebar

Install

npm i @renditions/get-img-sizes

Weekly Downloads

0

Version

0.0.5

License

Apache-2.0

Unpacked Size

14.4 kB

Total Files

8

Last publish

Collaborators

  • srilq