Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-cloudinary-lazy-image

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-cloudinary-lazy-image

Lazy-loading React image component based on Cloudinary api

  • 1.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

react-cloudinary-lazy-image

Optimised images with Cloudinary.

'react-cloudinary-lazy-image' is React component which cover "blur-up" effect, lazy-loading and formatting. The component is based on Gatsby image by Kyle Mathew, however instead of GraphQL and Gatsby it uses Cloudinary API. Have a speed and optimized gatsby-images without gatsby.

Covers

  1. Downsize larger images to the size needed by your design - even on desktop there is no need to get as big image as possible.
  2. Remove metadata from delivered images - by default images contain a lot of information useful for cameras and graphics applications, but not for web users.
  3. Format images to newer formats like JPEG-XR and WebP - common formats like PNG, JPG or GIF are not optimised to be send wireless.
  4. Lower image quality - many images have extra-high resolution, however it’s possible to lower quality without a significant visual impact.
  5. Downsize images on smaller device - display images for mobile users faster as there is probably slower internet connection.
  6. Lazy load images - allow images to download only when user scroll to it allows to speed up initial page load.
  7. Hold position of element - page doesn’t jump while images load.
  8. “Blur-up” technique - show very low resolution image before the original loads.

Points 1-4 are handled by Cloudinary.

Install

npm install react-cloudinary-lazy-image --save

How to use

Fixed example:

import React from 'react'
import Img from 'react-cloudinary-lazy-image'

export default ({publicId}) => (
    <div>
        <h1>Lazy-image with Cloudinary</h1>
        <Img
            cloudName={'cloud'}
            imageName={publicId}
            fixed={{
                width: 300,
                height: 300
            }}
            urlParams={'g_face,c_lfill'}
        />
    </div>
)

Fluid example:

import React from 'react'
import Img from 'react-cloudinary-lazy-image'

export default ({publicId}) => (
    <div>
        <h1>Lazy-image with Cloudinary</h1>
        <Img
            cloudName={'cloud'}
            imageName={publicId}
            fluid={{
                maxWidth: 300,
                height: 300
            }}
            style={{
                width: '40vw',
                height: '20vh'
            }}
        />
    </div>
)

Two types

Same as in gatsby-image there are two types of responsive images. Fixed and fluid.

  1. Images with fixed height and width. Cover double pixel density for retina display.
  2. Images in fluid container. Takes smallest possible picture to fill container. Configurable step allow you to have control over breakpoints.

Image transformation

You can set image transformation according to Cloudinary documentation, by setting urlParams. You can also find all formats that can be passed to imgFormat prop or get more info about quality prop.

Props

NameTypeDescription
fixedobjectObject with 'width' and 'height' properties
fluidobjectObject with 'maxWidth' required property. Optionally step, default=150 and 'height'. If height not set, uses 'c_scale' otherwise 'c_lfill'
fadeInboolDefaults to fading in the image on load
cloudNamestringCloudinary cloud name, default=process.env.CLOUD_NAME or process.env.REACT_APP_CLOUD_NAME
imageNamestringCloudinary publicId
urlParamsstringCloudinary image transformations params. Overrides default 'c_lfill' or 'c_scale'. If both weight and height (w_, h_) params are set srcSet will not be created.
titlestringPassed to the img element
altstringPassed to the img element
styleobjectSpread into the default styles of the wrapper element
imgStyleobjectSpread into the default styles of the actual img element
placeholderStyleobjectSpread into the default styles of the placeholder img element
backgroundColorstring / boolSet a colored background placeholder instead of "blur-up". If true, uses default "lightgray" color. You can also pass in any valid color string.
onLoadfuncA callback that is called when the full-size image has loaded.
onErrorfuncA callback that is called when the image fails to load.
imgFormatstring / boolAllow Cloudinary to format image. By default is set to 'f_auto'. Can be switch off by passing 'false' or be formatted to specific format (ex. 'webp')
qualitystring / boolAllow Cloudinary to change quality of image. By default is set to 'q_auto'. Can be switch off by passing 'false' or to specific value (ex. 'best')
versionstringSet Cloudinary optional version param. Doc.
blurSizenumberWidth of the low quality image. Default = 20.
blurUrlParamsstringCloudinary image transformations params for blur version.
useUrlParamsToBlurboolFlag to use urlParams for blur version. Overrides blurUrlParams.
IOParamsobjectPassed to window.intersectionObserver options. Default: { rootMargin: '200px' }

Keywords

FAQs

Package last updated on 02 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc