Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
react-cloudinary-lazy-image
Advanced tools
Lazy-loading React image component based on Cloudinary api
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.
Points 1-4 are handled by Cloudinary.
npm install react-cloudinary-lazy-image --save
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>
)
Same as in gatsby-image there are two types of responsive images. Fixed and fluid.
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.
Name | Type | Description |
---|---|---|
fixed | object | Object with 'width' and 'height' properties |
fluid | object | Object with 'maxWidth' required property. Optionally step, default=150 and 'height'. If height not set, uses 'c_scale' otherwise 'c_lfill' |
fadeIn | bool | Defaults to fading in the image on load |
cloudName | string | Cloudinary cloud name, default=process.env.CLOUD_NAME or process.env.REACT_APP_CLOUD_NAME |
imageName | string | Cloudinary publicId |
urlParams | string | Cloudinary 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. |
title | string | Passed to the img element |
alt | string | Passed to the img element |
style | object | Spread into the default styles of the wrapper element |
imgStyle | object | Spread into the default styles of the actual img element |
placeholderStyle | object | Spread into the default styles of the placeholder img element |
backgroundColor | string / bool | Set a colored background placeholder instead of "blur-up". If true, uses default "lightgray" color. You can also pass in any valid color string. |
onLoad | func | A callback that is called when the full-size image has loaded. |
onError | func | A callback that is called when the image fails to load. |
imgFormat | string / bool | Allow 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') |
quality | string / bool | Allow 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') |
version | string | Set Cloudinary optional version param. Doc. |
blurSize | number | Width of the low quality image. Default = 20. |
blurUrlParams | string | Cloudinary image transformations params for blur version. |
useUrlParamsToBlur | bool | Flag to use urlParams for blur version. Overrides blurUrlParams . |
IOParams | object | Passed to window.intersectionObserver options. Default: { rootMargin: '200px' } |
FAQs
Lazy-loading React image component based on Cloudinary api
The npm package react-cloudinary-lazy-image receives a total of 12 weekly downloads. As such, react-cloudinary-lazy-image popularity was classified as not popular.
We found that react-cloudinary-lazy-image demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.