npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

image-cropper-react

v1.0.1

Published

A lightweight and customizable React image cropper component with drag, resize,zoom and keyboard support. Export cropped images as Base64, Blob, or File — with square and circular crop box options.

Downloads

13

Readme

image-cropper-react - A Lightweight React Image Cropper Component for Avatar Uploads and Image Editing

image-cropper-react is a lightweight and customizable React image cropper component for cropping images using drag, zoom, resize, or keyboard input.
Perfect for avatar upload, image editors, and cropping tools in React applications.

Supports exporting cropped images as Base64, Blob, or File, with options for square or circle crop areas.


Table of Contents


Why Use image-cropper-react?

This package provides a lightweight, customizable, and dependency-free image cropping solution for React developers. It supports both square and circle crop boxes, offers drag and resize functionalities, and is fully controllable via props and ref. Whether you're creating an avatar upload feature or an image editing tool, image-cropper-react is perfect for your project.


Features

  • Lightweight and no external dependencies
  • Drag to move crop box
  • Resize crop area from corners
  • Zoom image using mouse wheel
  • Square or Circle crop modes
  • Keyboard arrow key support (with Shift for resizing)
  • Export cropped image as Base64, Blob, or File
  • Fully controllable via props and ref

Installation

To install image-cropper-react, run the following command:


npm install image-cropper-react

# or
yarn add image-cropper-react

Usage

import React, { useRef, useState } from "react";
import Cropper from "image-cropper-react"; 
import { Crop } from "./types";

const App = () => {
  const cropperRef = useRef<any>(null);
  const [crop, setCrop] = useState<Crop>({ x: 0, y: 0, width: 100, height: 100 });

  const handleCropChange = (newCrop: Crop) => {
    setCrop(newCrop);
  };

  const handleCropComplete = (cropped: string | Blob | File) => {
    console.log("Cropped output:", cropped);
  };

  const triggerCrop = () => {
    cropperRef.current?.triggerCropComplete();
  };

  return (
    <div>
      <Cropper
        ref={cropperRef}
        src="your-image-url.jpg"
        crop={crop}
        onCropChange={handleCropChange}
        onCropComplete={handleCropComplete}
        format="file" // "base64", "blob", or "file"
        cropBoxType="square" // or "circle"
      />

      <button onClick={triggerCrop}>Crop Image</button>
    </div>
  );
};

export default App;

JavaScript (JSX)

import React, { useRef, useState } from "react";
import Cropper from "image-cropper-react";

const App = () => {
  const cropperRef = useRef(null);
  const [crop, setCrop] = useState({ x: 0, y: 0, width: 100, height: 100 });

  const handleCropChange = (newCrop) => {
    setCrop(newCrop);
  };

  const handleCropComplete = (cropped) => {
    console.log("Cropped output:", cropped);
  };

  const triggerCrop = () => {
    cropperRef.current?.triggerCropComplete();
  };

  return (
    <div>
      <Cropper
        ref={cropperRef}
        src="your-image-url.jpg"
        crop={crop}
        onCropChange={handleCropChange}
        onCropComplete={handleCropComplete}
        format="file" // "base64", "blob", or "file"
        cropBoxType="square" // or "circle"
      />
      <button onClick={triggerCrop}>Crop Image</button>
    </div>
  );
};

export default App;

Props

| Prop | Type | Default | Description | | ---------------- | ----------------------------- | ---------- | ------------------------------------------------ | | src | string | required | Image source URL | | crop | { x: number; y: number; width: number; height: number } | required | Crop box dimensions | | onCropChange | (crop: Crop) => void | required | Callback when crop is moved or resized | | onCropComplete | (cropped: string \| Blob \| File) => void | optional | Callback when cropping is completed | | format | "base64" \| "blob" \| "file" | "file" | Output format of cropped result | | cropBoxType | "square" \| "circle" | "square" | Shape of the crop box |


Ref Methods

| Method | Description | | --------------------- | ---------------------------------- | | triggerCropComplete | Manually trigger crop and export |

Example:

cropperRef.current?.triggerCropComplete();

Crop Box Behavior

  • Drag inside the box to move it.
  • Resize from any corner using mouse.
  • Use the mouse wheel to zoom in and out of the image.
  • Hold Shift key while using arrow keys for resizing.
  • Press Enter to trigger crop completion by keyboard.

Links


Keywords

React image cropper, crop image in React, image cropper for React, cropper React component, avatar cropper React, React crop component, crop image React npm, image-cropper-react, React image cropper component, image cropping React, image cropper React library, image cropper for React apps, image cropper React UI


License

MIT License © 2025
Developed with ❤️