I Open-Sourced a 4kb, 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
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
| Feature | Why it matters |
|---|---|
| 4kb gzipped, zero deps | No bloat in your bundle |
| 100% client-side | Images never leave the browser |
| Strict TypeScript | Full types on props, refs, and exports |
| Tailwind / shadcn ready | No CSS fights — just drop it in |
| Pinch-to-zoom + touch | Works beautifully on mobile |
| Built-in circular crop |
borderRadius={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)
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
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
| Prop | Type | Default | Notes |
|---|---|---|---|
src |
string |
required | URL or data URL |
aspectRatio |
number |
free |
1, 16/9, 4/3... |
borderRadius |
number |
0 |
0–50 (50 = circle) |
outputFormat |
`"png" \ | "jpg" \ | "webp"` |
showGrid |
boolean |
true |
Rule-of-thirds |
minZoom / maxZoom
|
number |
1 / 5
|
— |
onCropChange |
(crop) => void |
— | Fires on every move |
disabled |
boolean |
false |
— |
🔐 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.
🔗 Links
- 📦 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
- ☕ Support: Buy me a coffee
💬 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! 🖼️
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.