Gathering detailed insights and metrics for react-avatar-editor
Gathering detailed insights and metrics for react-avatar-editor
Gathering detailed insights and metrics for react-avatar-editor
Gathering detailed insights and metrics for react-avatar-editor
@types/react-avatar-editor
TypeScript definitions for react-avatar-editor
react-avatar-editor-v1
A React package that provides an easy-to-use avatar editor along with a customizable avatar display component.
react-profile
React Profile Editor, crop, upload, apply filters and adjust colors for your avatar image. Optimize the image size for your application
@edpi/react-avatar-editor
Avatar / profile picture component. Resize and crop your uploaded image using a intuitive user interface.
Small avatar & profile picture component. Resize and crop uploaded images using a intuitive user interface.
npm install react-avatar-editor
Typescript
Module System
Node Version
NPM Version
86.4
Supply Chain
91.5
Quality
78.7
Maintenance
100
Vulnerability
99.3
License
TypeScript (74.17%)
CSS (22.72%)
HTML (2.83%)
JavaScript (0.28%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,442 Stars
602 Commits
379 Forks
36 Watchers
2 Branches
66 Contributors
Updated on Jul 11, 2025
Latest Version
13.0.2
Package Id
react-avatar-editor@13.0.2
Unpacked Size
56.06 kB
Size
15.68 kB
File Count
11
NPM Version
10.2.3
Node Version
20.10.0
Published on
Dec 20, 2023
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
31
Facebook like, avatar / profile picture component. Resize, crop and rotate your uploaded image using a clear user interface.
Just use yarn or npm to add it to your project:
yarn add react-avatar-editor
respective
npm install --save react-avatar-editor
1import React from 'react' 2import AvatarEditor from 'react-avatar-editor' 3 4class MyEditor extends React.Component { 5 render() { 6 return ( 7 <AvatarEditor 8 image="http://example.com/initialimage.jpg" 9 width={250} 10 height={250} 11 border={50} 12 color={[255, 255, 255, 0.6]} // RGBA 13 scale={1.2} 14 rotate={0} 15 /> 16 ) 17 } 18} 19 20export default MyEditor
Prop | Type | Description |
---|---|---|
image | String|File | The URL of the image to use, or a File (e.g. from a file input). |
width | Number | The total width of the editor. |
height | Number | The total height of the editor. |
border | Number|Number[] | The cropping border. Image will be visible through the border, but cut off in the resulting image. Treated as horizontal and vertical borders when passed an array. |
borderRadius | Number | The cropping area border radius. |
color | Number[] | The color of the cropping border, in the form: [red (0-255), green (0-255), blue (0-255), alpha (0.0-1.0)]. |
backgroundColor | String | The background color of the image if it's transparent. |
style | Object | Styles for the canvas element. |
scale | Number | The scale of the image. You can use this to add your own resizing slider. |
position | Object | The x and y co-ordinates (in the range 0 to 1) of the center of the cropping area of the image. Note that if you set this prop, you will need to keep it up to date via onPositionChange in order for panning to continue working. |
rotate | Number | The rotation degree of the image. You can use this to rotate image (e.g 90, 270 degrees). |
crossOrigin | String | The value to use for the crossOrigin property of the image, if loaded from a non-data URL. Valid values are "anonymous" and "use-credentials" . See this page for more information. |
className | String|String[] | className property passed to the canvas element |
onLoadFailure(event) | function | Invoked when an image (whether passed by props or dropped) load fails. |
onLoadSuccess(imgInfo) | function | Invoked when an image (whether passed by props or dropped) load succeeds. |
onImageReady(event) | function | Invoked when the image is painted on the canvas the first time. |
onMouseUp() | function | Invoked when the user releases their mouse button after interacting with the editor. |
onMouseMove(event) | function | Invoked when the user hold and moving the image. |
onImageChange() | function | Invoked when the user changed the image. Not invoked on the first render, and invoked multiple times during drag, etc. |
onPositionChange() | function | Invoked when the user pans the editor to change the selected area of the image. Passed a position object in the form { x: 0.5, y: 0.5 } where x and y are the relative x and y coordinates of the center of the selected area. |
disableBoundaryChecks | Boolean | Set to true to allow the image to be moved outside the cropping boundary. |
disableHiDPIScaling | Boolean | Set to true to disable devicePixelRatio based canvas scaling. Can improve perfermance of very large canvases on mobile devices. |
The resulting image will have the same resolution as the original image, regardless of the editor's size.
If you want the image sized in the dimensions of the canvas you can use getImageScaledToCanvas
.
1import React from 'react' 2import AvatarEditor from 'react-avatar-editor' 3 4class MyEditor extends React.Component { 5 onClickSave = () => { 6 if (this.editor) { 7 // This returns a HTMLCanvasElement, it can be made into a data URL or a blob, 8 // drawn on another canvas, or added to the DOM. 9 const canvas = this.editor.getImage() 10 11 // If you want the image resized to the canvas size (also a HTMLCanvasElement) 12 const canvasScaled = this.editor.getImageScaledToCanvas() 13 } 14 } 15 16 setEditorRef = (editor) => (this.editor = editor) 17 18 render() { 19 return ( 20 <AvatarEditor 21 ref={this.setEditorRef} 22 image="http://example.com/initialimage.jpg" 23 width={250} 24 height={250} 25 border={50} 26 scale={1.2} 27 /> 28 ) 29 } 30} 31 32export default MyEditor
We recommend using react-dropzone. It allows you to add drag and drop support to anything really easy. Here is an example how to use it with react-avatar-editor:
1import React from 'react' 2import AvatarEditor from 'react-avatar-editor' 3import Dropzone from 'react-dropzone' 4 5class MyEditor extends React.Component { 6 state = { 7 image: 'http://example.com/initialimage.jpg', 8 } 9 10 handleDrop = (dropped) => { 11 this.setState({ image: dropped[0] }) 12 } 13 14 render() { 15 return ( 16 <Dropzone 17 onDrop={this.handleDrop} 18 noClick 19 noKeyboard 20 style={{ width: '250px', height: '250px' }} 21 > 22 {({ getRootProps, getInputProps }) => ( 23 <div {...getRootProps()}> 24 <AvatarEditor width={250} height={250} image={this.state.image} /> 25 <input {...getInputProps()} /> 26 </div> 27 )} 28 </Dropzone> 29 ) 30 } 31}
Sometimes you will need to get the cropping rectangle (the coordinates of the area of the image to keep), for example in case you intend to perform the actual cropping server-side.
getCroppingRect()
returns an object with four properties: x
, y
, width
and height
;
all relative to the image size (that is, comprised between 0 and 1). It is a method of AvatarEditor elements,
like getImage()
.
Note that: getImage()
returns a canvas element and if you want to use it in src
attribute of img
, convert it into a blob url.
1const canvas = this.editor.getImage().toDataURL(); 2let imageURL; 3fetch(canvas) 4 .then(res => res.blob()) 5 .then(blob => (imageURL = window.URL.createObjectURL(blob))); 6 7// Usage 8<img src={imageURL} ... />
For development you can use following build tools:
npm run build
: Builds the minified dist file: dist/index.js
npm run watch
: Watches for file changes and builds unminified into: dist/index.js
npm run demo:build
: Builds the demo based on the dist file dist/index.js
npm run demo:watch
: Run webpack-dev-server. Check demo website localhost:8080Kudos and thanks to danlee for the imporant work & many contributions to this project! Also thanks to oyeanuj, mtlewis and hu9o and all other awesome people contributing to this.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 11/18 approved changesets -- score normalized to 6
Reason
2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
15 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