Gathering detailed insights and metrics for kpfromer-react-optimized-image
Gathering detailed insights and metrics for kpfromer-react-optimized-image
Gathering detailed insights and metrics for kpfromer-react-optimized-image
Gathering detailed insights and metrics for kpfromer-react-optimized-image
Easy to use React components for optimized-images-loader / next-optimized-images.
npm install kpfromer-react-optimized-image
Typescript
Module System
Node Version
NPM Version
TypeScript (61.23%)
JavaScript (38.77%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
48 Commits
1 Branches
1 Contributors
Updated on Jan 26, 2021
Latest Version
0.5.0
Package Id
kpfromer-react-optimized-image@0.5.0
Unpacked Size
70.71 kB
Size
18.47 kB
File Count
29
NPM Version
6.14.11
Node Version
12.20.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
36
Features:
This image components requires optimized-images-loader to already be installed and configured.
If you are using Next.js, you can use the next-optimized-images plugin instead for easier configuration.
npm install react-optimized-image
Add the react-optimized-image/plugin
babel plugin to your .babelrc
file.
If you don't yet have a .babelrc
file, create one with the following content:
1{ 2 "plugins": ["react-optimized-image/plugin"] 3}
You can now import or require your images directly in your react components:
1import React from 'react'; 2import Img from 'react-optimized-image'; 3import Header from './images/header.jpg'; 4 5export default () => ( 6 <div> 7 {/* with import statement ..*/} 8 <Img src={Header} /> 9 10 {/* ..or an inline require */} 11 <Img src={require('./images/my-small-image.png')} /> 12 </div> 13); 14 15/** 16 * Results in: 17 * 18 * <div> 19 * <img src="/_next/static/chunks/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg" /> 20 * <img src="data:image/png;base64,..." /> 21 * </div> 22 */
For easier use and full typescript support, this plugin provides some image components.
The Img
component can be used to include a normal image. Additionally, it can create a WebP fallback and provide different sizes for different viewports.
1import Img from 'react-optimized-image'; 2import MyImage from './images/my-image.jpg'; 3 4export default () => ( 5 <> 6 <h1>Normal optimized image</h1> 7 <Img src={MyImage} /> 8 9 <h1>Image will be resized to 400px width</h1> 10 <Img src={MyImage} sizes={[400]} /> 11 12 <h1>A WebP image will be served in two sizes: 400px and 800px</h1> 13 <h2>As a fallback, a jpeg image will be provided (also in both sizes)</h2> 14 <Img src={MyImage} webp sizes={[400, 800]} /> 15 </> 16); 17 18/** 19 * Results in: 20 * 21 * <h1>Normal optimized image</h1> 22 * <img src="/_next/static/chunks/images/my-image-5216de428a8e8bd01a4aa3673d2d1391.jpg" /> 23 * 24 * <h1>Image will be resized to 400px width</h1> 25 * <img src="/_next/static/chunks/images/my-image-572812a2b04ed76f93f05bf57563c35d.jpg" /> 26 * 27 * <h1>A WebP image will be served in two sizes: 400px and 800px</h1> 28 * <h2>As a fallback, a jpeg image will be provided (also in both sizes)</h2> 29 * <picture> 30 * <source type="image/webp" srcset="/_next/static/chunks/images/image-0cc3dc9faff2e36867d4db3de15a7b32.webp" media="(max-width: 400px)"> 31 * <source type="image/webp" srcset="/_next/static/chunks/images/image-08ce4cc7914a4d75ca48e9ba0d5c65da.webp" media="(min-width: 401px)"> 32 * <source type="image/jpeg" srcset="/_next/static/chunks/images/image-132d7f8860bcb758e97e54686fa0e240.jpg" media="(max-width: 400px)"> 33 * <source type="image/jpeg" srcset="/_next/static/chunks/images/image-9df4a476716a33461114a459e64301df.jpg" media="(min-width: 401px)"> 34 * <img src="/_next/static/chunks/images/image-0f5726efb3915365a877921f93f004cd.jpg"></picture> 35 * </picture> 36 */
Prop | Required | Type | Description |
---|---|---|---|
src | yes | string | Source image. |
webp | boolean | If true, the image will get converted to WebP. For browsers which don't support WebP, an image in the original format will be served. | |
sizes | number[] | Resize the image to the given width. If only one size is present, an <img> tag will get generated, otherwise a <picture> tag for multiple sizes. | |
densities | number[] | Default: [1] Specifies the supported pixel densities. For example, to generate images for retina displays, set this value to [1, 2] . | |
breakpoints | number[] | Specifies the breakpoints used to decide which image size to use (when the size property is present). If no breakpoints are specified, they will automatically be set to match the image sizes which is good for full-width images but result in too big images in other cases.The breakpoints should have the same order as the image sizes. Example for this query: sizes={[400, 800, 1200]} breakpoints={[600, 1000]} For widths 0px-600px the 400px image will be used, for 601px-1000px the 800px image will be used and for everything larger than 1001px, the 1200px image will be used. | |
inline | boolean | If true, the image will get forced to an inline data-uri (e.g. data:image/png;base64,... ). | |
url | boolean | If true, the image will get forced to be referenced with an url, even if it is a small image and would get inlined by default. | |
original | boolean | If true, the image will not get optimized (but still resized if the sizes property is present). | |
type | string | So you don't have to repeat yourself by setting the same sizes or other properties on many images, specify the image type which equals to one in your global image config. | |
anything else | ImgHTMLAttributes | All other properties will be directly passed to the <img> tag. So it would for example be possible to use native lazy-loading with loading="lazy" . |
The Svg
includes an svg file directly into the HTML so it can be styled by CSS. If you don't want to include them directly in the HTML, you can also use svg images together with the Img
component which will reference it by the URL.
1import { Svg } from 'react-optimized-image'; 2import Icon from './icons/my-icon.svg'; 3 4export default () => ( 5 <> 6 <h1>SVG will be directly included in the HTML</h1> 7 <Svg src={Icon} className="fill-red" /> 8 </> 9); 10 11/** 12 * Results in: 13 * 14 * <span><svg class="fill-red" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="280" height="330"><g><path>...</path></g></svg></span> 15 */
Prop | Required | Type | Description |
---|---|---|---|
src | yes | string | Source image. |
className | string | Class to apply to the <svg> tag. |
The images.config.js
file contains default image optimization options and is located in the root of your project.
Available options:
Option | Type | Description |
---|---|---|
default | ImgProps | Properties specified within the default key will get applied to all usages of the Img components.All properties of the Img component can be set. For example, to convert all your images to WebP, set { webp: true } . |
types | Record<string, ImgProps> | Instead of specifying options for all images with the default key, you can create as many image types as you want. Those can also contain all properties of the Img component. The options specified in the default key will also get applied here if they are not overwritten. |
1// images.config.js 2 3module.exports = { 4 default: { 5 webp: true, 6 }, 7 types: { 8 thumbnail: { 9 sizes: [200, 400], 10 breakpoints: [800], 11 webp: false, 12 }, 13 }, 14};
This will convert all images to WebP. The images with the thumbnail
type will be generated in two sizes (200, 400) but not converted to WebP. If webp: false
would not be present, it would get inherited from the default
key.
1import React from 'react'; 2import Img from 'react-optimized-image'; 3import MyImage from './images/my-image.jpg'; 4 5export default () => ( 6 <div> 7 {/* This will get converted into a WebP image (while still providing a fallback image). */} 8 <Img src={MyImage} /> 9 10 {/* This will be provided in to sizes (200, 400) but not get converted to WebP. */} 11 <Img src={MyImage} type="thumbnail" /> 12 </div> 13);
Licensed under the MIT license.
© Copyright Cyril Wanner
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no SAST tool detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
54 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More