Mohammad Shehadeh

Image Cropper

Component 1

About

Pan-and-zoom image cropper on react-easy-crop: rect or round mask, fixed aspect, zoom slider and canvas export via ref.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Image Cropper to your project and fits it to your theme.

Code

How Image Cropper is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";

import {
  ImageCropper,
  ImageCropperZoom,
  type ImageCropperRef,
} from "@/components/ui/image-cropper";

export default function ImageCropperDemo() {
  const cropperRef = React.useRef<ImageCropperRef>(null);
  const [output, setOutput] = React.useState<string | null>(null);

  return (
    <div className="mx-auto grid w-full max-w-sm gap-4">
      <ImageCropper
        ref={cropperRef}
        src="https://cdn.21st.dev/assets/mirror/7d/7dc329d98d9641a0bd8d86e7b2cff7245b9d423d7dac61bb273eef68fe53f284.jpg"
        alt="Sample photo"
        aspect={1}
        shape="round"
        grid
      >
        <ImageCropperZoom />
      </ImageCropper>
      <div className="flex items-center gap-3">
        <button
          type="button"
          onClick={() =>
            setOutput(
              cropperRef.current?.getCroppedDataUrl({ size: 256 }) ?? null,
            )
          }
          className="inline-flex h-9 items-center justify-center rounded-md bg-primary px-4 text-sm font-medium text-primary-foreground"
        >
          Crop
        </button>
        {output && (
          // eslint-disable-next-line @next/next/no-img-element
          <img
            src={output}
            alt="Cropped result"
            className="size-12 rounded-full border border-border"
          />
        )}
      </div>
    </div>
  );
}

More by Mohammad Shehadeh

View all
  • Feature Problem Cards

    Feature Problem Cards

    84
  • Feature Grid Spotlight Cards

    Feature Grid Spotlight Cards

    70
  • Dithered Shader CTA

    Dithered Shader CTA

    63
  • Ecommerce Category Page

    Ecommerce Category Page

    61
  • Split Login

    Split Login

    60
  • Comparison Table

    Comparison Table

    59
  • FAQ Two Column

    FAQ Two Column

    59
  • Comparison Section

    Comparison Section

    57

Explore more

Part of Hirael — browse the full library on 21st.dev.