react-image-crop vs react-easy-crop vs react-avatar-editor vs react-cropper
React Image Cropping Libraries Comparison
1 Year
react-image-cropreact-easy-cropreact-avatar-editorreact-cropperSimilar Packages:
What's React Image Cropping Libraries?

Image cropping libraries in React provide developers with tools to allow users to select and crop images within their applications. These libraries enhance user experience by enabling image manipulation directly in the browser, which is essential for applications that require user-uploaded images, such as profile picture uploads or image galleries. Each library offers unique features and functionalities that cater to different use cases, from simple cropping to advanced editing capabilities.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-image-crop503,7923,931111 kB686 months agoISC
react-easy-crop436,5302,451522 kB142 hours agoMIT
react-avatar-editor201,8082,40957.4 kB27a year agoMIT
react-cropper201,4792,04420.5 kB162 years agoMIT
Feature Comparison: react-image-crop vs react-easy-crop vs react-avatar-editor vs react-cropper

User Experience

  • react-image-crop:

    react-image-crop balances functionality and usability, offering a straightforward cropping interface while allowing for customization. Users can easily adjust the crop area, making it suitable for applications that need both simplicity and flexibility.

  • react-easy-crop:

    react-easy-crop is designed for simplicity, providing a clean and intuitive interface that allows users to quickly crop images without overwhelming them with options. This makes it ideal for applications where ease of use is paramount.

  • react-avatar-editor:

    react-avatar-editor offers a user-friendly interface that allows users to easily crop their avatars with minimal setup. It provides immediate feedback on the cropping process, enhancing the overall user experience for applications focused on profile images.

  • react-cropper:

    react-cropper provides a highly interactive cropping experience with features like zooming, rotating, and aspect ratio adjustments. This level of interactivity makes it suitable for applications that require detailed image manipulation, ensuring users have full control over their cropping choices.

Customization

  • react-image-crop:

    react-image-crop offers a good level of customization, allowing developers to define crop dimensions, aspect ratios, and more. This makes it a versatile choice for applications that require tailored cropping solutions.

  • react-easy-crop:

    react-easy-crop allows for basic customization of the cropping area but is designed to be lightweight. It provides essential features without overwhelming users with too many options, making it suitable for projects that need a simple yet flexible cropping solution.

  • react-avatar-editor:

    react-avatar-editor offers limited customization options, focusing primarily on avatar cropping. It allows for basic adjustments but may not meet the needs of applications requiring extensive image editing features.

  • react-cropper:

    react-cropper excels in customization, providing a wide range of options for adjusting the cropping area, aspect ratios, and even image transformations. This makes it suitable for applications that require specific cropping functionalities and detailed image adjustments.

Performance

  • react-image-crop:

    react-image-crop is also designed for good performance, allowing for responsive cropping without significant delays. It balances functionality and efficiency, making it a reliable choice for various applications.

  • react-easy-crop:

    react-easy-crop is lightweight and performs well, ensuring quick rendering and responsiveness during cropping. Its minimalistic design contributes to its performance, making it ideal for applications where speed is crucial.

  • react-avatar-editor:

    react-avatar-editor is optimized for performance with a canvas-based approach, ensuring that image processing is efficient and responsive. This is particularly beneficial for applications with a focus on real-time image editing.

  • react-cropper:

    react-cropper is built on Cropper.js, which is known for its performance efficiency. It handles large images well and provides smooth interactions, making it suitable for applications that require handling high-resolution images without lag.

Learning Curve

  • react-image-crop:

    react-image-crop has a moderate learning curve, offering a balance between simplicity and functionality. Developers can quickly grasp its core features while still having the ability to implement more complex functionalities as needed.

  • react-easy-crop:

    react-easy-crop is designed to be user-friendly with a simple API, making it easy for developers to get started quickly. This is advantageous for projects that need to be implemented rapidly without extensive learning.

  • react-avatar-editor:

    react-avatar-editor has a gentle learning curve, making it easy for developers to implement and customize. Its straightforward API allows for quick integration into projects, which is beneficial for beginners.

  • react-cropper:

    react-cropper has a steeper learning curve due to its extensive features and options. Developers may need to invest more time to fully understand and utilize its capabilities, making it better suited for those with more experience.

Community and Support

  • react-image-crop:

    react-image-crop has a moderate community presence with adequate documentation. While it may not have as many resources as larger libraries, it still provides sufficient support for developers looking to implement its features.

  • react-easy-crop:

    react-easy-crop has a growing community and offers decent documentation, making it accessible for developers. Its simplicity contributes to a quicker understanding of its functionalities, though resources may be less extensive than larger libraries.

  • react-avatar-editor:

    react-avatar-editor has a smaller community compared to other libraries, which may result in limited resources and support. However, its simplicity makes it easy to find basic documentation and examples.

  • react-cropper:

    react-cropper benefits from a larger community and extensive documentation due to its foundation on Cropper.js. This provides developers with ample resources, tutorials, and community support, making it easier to troubleshoot issues.

How to Choose: react-image-crop vs react-easy-crop vs react-avatar-editor vs react-cropper
  • react-image-crop:

    Choose react-image-crop if you need a library that offers a balance between simplicity and customization. It allows for responsive cropping and provides a variety of options for controlling the crop area, making it ideal for applications that require more control over the cropping process.

  • react-easy-crop:

    Opt for react-easy-crop if you want a lightweight and flexible solution that provides a simple API for cropping images. It is designed to be easy to integrate and use, making it suitable for projects that prioritize simplicity and performance without sacrificing functionality.

  • react-avatar-editor:

    Choose react-avatar-editor if you need a straightforward solution for avatar cropping with a focus on simplicity and ease of use. It provides a canvas-based approach that allows for real-time image editing, making it ideal for applications that require user avatars.

  • react-cropper:

    Select react-cropper if you require a more feature-rich cropping solution that includes advanced functionalities like rotation, zooming, and aspect ratio control. It is built on top of Cropper.js and offers a comprehensive set of options for fine-tuning the cropping experience.

README for react-image-crop

React Image Crop

An image cropping tool for React with no dependencies.

React Image Crop on NPM

CodeSandbox Demo

ReactCrop GIF

Table of Contents

  1. Features
  2. Installation
  3. Usage
  4. Example
  5. CDN
  6. Props
  7. FAQ
    1. How can I generate a crop preview in the browser?
    2. How to correct image EXIF orientation/rotation?
    3. How to filter, rotate and annotate?
    4. How can I center the crop?
  8. Contributing / Developing

Features

  • Responsive (you can use pixels or percentages).
  • Touch enabled.
  • Free-form or fixed aspect crops.
  • Fully keyboard accessible (a11y).
  • No dependencies/small footprint (<5KB gzip).
  • Min/max crop size.
  • Crop anything, not just images.

If React Crop doesn't cover your requirements then take a look at Pintura (our sponsor). It features cropping, rotating, filtering, annotation, and lots more.

Learn more about Pintura here

Installation

npm i react-image-crop --save
yarn add react-image-crop
pnpm add react-image-crop

This library works with all modern browsers. It does not work with IE.

Usage

Include the main js module:

import ReactCrop from 'react-image-crop'

Include either dist/ReactCrop.css or ReactCrop.scss.

import 'react-image-crop/dist/ReactCrop.css'
// or scss:
import 'react-image-crop/src/ReactCrop.scss'

Example

import ReactCrop, { type Crop } from 'react-image-crop'

function CropDemo({ src }) {
  const [crop, setCrop] = useState<Crop>()
  return (
    <ReactCrop crop={crop} onChange={c => setCrop(c)}>
      <img src={src} />
    </ReactCrop>
  )
}

See the sandbox demo for a more complete example.

CDN

<link href="https://unpkg.com/react-image-crop/dist/ReactCrop.css" rel="stylesheet" />
<script src="https://unpkg.com/react-image-crop/dist/index.umd.cjs"></script>

Note when importing the script globally using a <script> tag access the component with ReactCrop.Component.

Props

onChange: (crop: PixelCrop, percentCrop: PercentCrop) => void

A callback which happens for every change of the crop (i.e. many times as you are dragging/resizing). Passes the current crop state object.

Note you must implement this callback and update your crop state, otherwise nothing will change!

<ReactCrop crop={crop} onChange={(crop, percentCrop) => setCrop(crop)} />

crop and percentCrop are interchangeable. crop uses pixels and percentCrop uses percentages to position and size itself. Percent crops are resistant to image/media resizing.

crop?: Crop

Starting with no crop:

const [crop, setCrop] = useState<Crop>()

<ReactCrop crop={crop} onChange={c => setCrop(c)}>
  <img src={src} />
</ReactCrop>

Starting with a preselected crop:

const [crop, setCrop] = useState<Crop>({
  unit: '%', // Can be 'px' or '%'
  x: 25,
  y: 25,
  width: 50,
  height: 50
})

<ReactCrop crop={crop} onChange={c => setCrop(c)}>
  <img src={src} />
</ReactCrop>

⚠️ You must ensure the crop is in bounds and correct to the aspect ratio if manually setting. Aspect ratios can be tricky when using %. You can make use of centerCrop and makeAspectCrop helpers. See How can I center the crop? or the CodeSanbox Demo for examples.

aspect?: number

The aspect ratio of the crop, e.g. 1 for a square or 16 / 9 for landscape. Omit/pass undefined for a free-form crop.

minWidth?: number

A minimum crop width, in pixels.

minHeight?: number

A minimum crop height, in pixels.

maxWidth?: number

A maximum crop width, in pixels.

maxHeight?: number

A maximum crop height, in pixels.

keepSelection?: boolean

If true is passed then selection can't be disabled if the user clicks outside the selection area.

disabled?: boolean

If true then the user cannot resize or draw a new crop. A class of ReactCrop--disabled is also added to the container for user styling.

locked?: boolean

If true then the user cannot create or resize a crop, but can still drag the existing crop around. A class of ReactCrop--locked is also added to the container for user styling.

className?: string

A string of classes to add to the main ReactCrop element.

style?: React.CSSProperties

Inline styles object to be passed to the image wrapper element.

onComplete?: (crop: PixelCrop, percentCrop: PercentCrop) => void

A callback which happens after a resize, drag, or nudge. Passes the current crop state object.

percentCrop is the crop as a percentage. A typical use case for it would be to save it so that the user's crop can be restored regardless of the size of the image (for example saving it on desktop, and then using it on a mobile where the image is smaller).

onDragStart?: (e: PointerEvent) => void

A callback which happens when a user starts dragging or resizing. It is convenient to manipulate elements outside this component.

onDragEnd?: (e: PointerEvent) => void

A callback which happens when a user releases the cursor or touch after dragging or resizing.

renderSelectionAddon?: (state: ReactCropState) => React.ReactNode

Render a custom element inside the crop selection.

ruleOfThirds?: boolean

Show rule of thirds lines in the cropped area. Defaults to false.

circularCrop?: boolean

Show the crop area as a circle. If your aspect is not 1 (a square) then the circle will be warped into an oval shape. Defaults to false.

FAQ

How can I generate a crop preview in the browser?

This isn't part of the library but there is an example over here CodeSandbox Demo.

How to correct image EXIF orientation/rotation?

You might find that some images are rotated incorrectly. Unfortunately this is a browser wide issue not related to this library. You need to fix your image before passing it in.

You can use the following library to load images, which will correct the rotation for you: https://github.com/blueimp/JavaScript-Load-Image/

You can read an issue on this subject here: https://github.com/sekoyo/react-image-crop/issues/181

If you're looking for a complete out of the box image editor which already handles EXIF rotation then consider using Pintura.

How to filter, rotate and annotate?

This library is deliberately lightweight and minimal for you to build features on top of. If you wish to perform more advanced image editing out of the box then consider using Pintura.

Pintura Demo

How can I center the crop?

The easiest way is to use the percentage unit:

crop: {
  unit: '%',
  width: 50,
  height: 50,
  x: 25,
  y: 25
}

Centering an aspect ratio crop is trickier especially when dealing with %. However two helper functions are provided:

  1. Listen to the load event of your media to get its size:
<ReactCrop crop={crop} aspect={16 / 9}>
  <img src={src} onLoad={onImageLoad} />
</ReactCrop>
  1. Use makeAspectCrop to create your desired aspect and then centerCrop to center it:
function onImageLoad(e) {
  const { naturalWidth: width, naturalHeight: height } = e.currentTarget

  const crop = centerCrop(
    makeAspectCrop(
      {
        // You don't need to pass a complete crop into
        // makeAspectCrop or centerCrop.
        unit: '%',
        width: 90,
      },
      16 / 9,
      width,
      height
    ),
    width,
    height
  )

  setCrop(crop)
}

Also remember to set your crop using the percentCrop on changes:

const onCropChange = (crop, percentCrop) => setCrop(percentCrop)

And your aspect prop should be set to the same value: <ReactCrop aspect={16 / 9} ... />.

Contributing / Developing

To develop run pnpm install && pnpm dev and open the localhost server in your browser. Update code and it will reload. When you're ready, open a pull request.