✨ New Release: PDF Redactor is live! True redaction & metadata removal with zero server uploads.
PrivateTools
Back to blog

Privacy-First React Image Cropper (Tailwind + TypeScript Ready)

A 4kb, zero-dependency React image cropper with strict TypeScript and Tailwind support. 100% client-side, privacy-first, pinch-to-zoom. Open-sourced on npm.

Privacy-First React Image Cropper (Tailwind + TypeScript Ready)

A few weeks ago, I was building PrivateTools — a suite of 60+ free, privacy-first online tools. One of the most-used tools? The image cropper.

The problem: every existing React cropper I tried had issues.

  • react-image-crop — partial TypeScript support, requires custom CSS.
  • react-easy-crop — no strict types, awkward Tailwind integration.
  • Cloud-based croppers — upload user photos to a server (privacy nightmare 🚩).

So I built my own. And today, I'm open-sourcing it.

📦 npm: https://www.npmjs.com/package/@privatetools/react-image-cropper 💻 GitHub: https://github.com/sikandardevbusiness/privatetools-packages 🌐 Live Demo: https://privatetools.in/tools/image/universal-image-cropper

🎯 Why This Cropper Is Different

FeatureWhy it matters
4kb gzipped, zero depsNo bloat in your bundle
100% client-sideImages never leave the browser
Strict TypeScriptFull types on props, refs, and exports
Tailwind / shadcn readyNo CSS fights — just drop it in
Pinch-to-zoom + touchWorks beautifully on mobile
Built-in circular cropborderRadius={50} → perfect avatars

🚀 Installation

npm install @privatetools/react-image-cropper
# or
pnpm add @privatetools/react-image-cropper
# or
yarn add @privatetools/react-image-cropper

📖 Usage

1. Basic Avatar Cropper (1:1 + Circle)

Live demo of the React image cropper showing circular crop, grid overlay and pinch-to-zoom The live demo: circular mask, rule-of-thirds grid and pinch-to-zoom, all running client-side.

import { useRef, useState } from "react";
import { Cropper, type CropperRef } from "@privatetools/react-image-cropper";

export default function AvatarUpload() {
  const cropperRef = useRef<CropperRef>(null);
  const [src, setSrc] = useState("/user-photo.jpg");

  async function handleCrop() {
    const blob = await cropperRef.current?.getCroppedBlob(0.92);
    if (!blob) return;

    // Upload anywhere — S3, Supabase, your API, whatever.
    const formData = new FormData();
    formData.append("avatar", blob, "avatar.png");
    await fetch("/api/upload", { method: "POST", body: formData });
  }

  return (
    <div className="mx-auto max-w-md space-y-4">
      <Cropper
        ref={cropperRef}
        src={src}
        aspectRatio={1}
        borderRadius={50}
        outputFormat="png"
        className="rounded-xl border border-zinc-200"
      />
      <button
        onClick={handleCrop}
        className="w-full rounded-md bg-blue-600 py-2 text-white hover:bg-blue-700"
      >
        Crop & Upload
      </button>
    </div>
  );
}

2. Free-Form Crop with Live Coordinates

Circle Image Cropper showing a circular mask with rule-of-thirds grid and a 50% border-radius slider The circular crop mode: set borderRadius to 50 for a perfect round mask, with the rule-of-thirds grid and live zoom controls.

import { useState } from "react";
import { Cropper, type CropArea } from "@privatetools/react-image-cropper";

export default function FreeCrop() {
  const [crop, setCrop] = useState<CropArea | null>(null);

  return (
    <div>
      <Cropper
        src="/landscape.jpg"
        onCropChange={(c) => setCrop(c)}
        showGrid
        minZoom={1}
        maxZoom={5}
      />
      <pre className="mt-4 text-xs">
        {JSON.stringify(crop, null, 2)}
      </pre>
    </div>
  );
}

3. Imperative API (Zoom, Reset, Data URL)

const cropperRef = useRef<CropperRef>(null);

// Zoom in programmatically
cropperRef.current?.setZoom(2.5);

// Get a preview instantly
const dataUrl = cropperRef.current?.getCroppedDataURL(0.9);
setPreview(dataUrl);

// Reset everything
cropperRef.current?.reset();

🧩 Props at a Glance

PropTypeDefaultNotes
srcstringrequiredURL or data URL
aspectRationumberfree1, 16/9, 4/3...
borderRadiusnumber00–50 (50 = circle)
outputFormat"png" | "jpg" | "webp""png"—
showGridbooleantrueRule-of-thirds
minZoom / maxZoomnumber1 / 5—
onCropChange(crop) => void—Fires on every move
disabledbooleanfalse—

🔐 The Privacy Angle (Why This Matters)

Most "free online croppers" quietly POST your image to their server. If a user is cropping a passport photo, a client mockup, or a medical scan — that's a data leak.

This cropper runs entirely inside the browser's Canvas API. No network calls. No analytics on image bytes. No server. Ever.

That's the whole reason I built PrivateTools in the first place.

💬 Feedback Wanted

I'd genuinely love to know:

  • What's missing for your use case?
  • Any Next.js / React 19 hydration issues on your end?
  • Should I add WebP quality sliders next?

Drop a comment 👇 — I read every one.

And if this saved you 2 hours of fighting with react-easy-crop, a ⭐ on GitHub goes a long way.

Happy cropping! 🖼️