Import
Usage
Props
Callback with base64-encoded WebP image after cropping and compression. The image is a data URL string (e.g.,
"data:image/webp;base64,...").Image source options. Default:
["library"]. On mobile, shows modal with both options if array has multiple values.Max height in pixels for compressed image. Uses compressorjs for resizing.
Max width in pixels for compressed image. Uses compressorjs for resizing.
Skip crop UI and immediately compress and return image. Useful for quick uploads without editing.
Custom button text. Default:
"Subir foto".Custom CSS properties for the upload button.
Custom icon for the upload button.
Custom CSS properties for the container.
Custom CSS properties for the crop preview canvas (shown in bottom-right during cropping).
Label text (currently not rendered in the component).
Features
Crop Tool
- 1:1 aspect ratio: Fixed square crop for profile photos
- Real-time preview: 150x150px preview in bottom-right corner
- Drag and resize: Interactive crop area
- Toolbar: “Recortar” button to confirm, X button to cancel
Compression
- Format: WebP (smaller file size than JPEG/PNG)
- Quality: 1 (maximum quality)
- Resizing: Respects maxHeight and maxWidth
- Library: Uses compressorjs
Webcam Capture
- Environment camera: Uses
facingMode: "environment"(rear camera on mobile) - Full-screen modal: Dedicated capture interface
- Capture button: Large circular button at bottom
- X button: Close and cancel capture
Mobile Support
- Source selection modal: Shows when
optionshas multiple values - Full-screen mode: Better UX on small screens
- Touch-friendly: Large tap targets
Examples
Profile Photo Upload
Document Upload (No Crop)
Library Only (No Camera)
Custom Button Style
Complete Upload Flow
Browser Support
Requires modern browser features:- MediaDevices API: For webcam access (
navigator.mediaDevices.getUserMedia) - Canvas API: For image cropping and preview
- FileReader API: For base64 conversion
- WebP support: For image compression (fallback may be needed for older browsers)
Dependencies
react-image-crop: Crop UI componentcompressorjs: Image compressionreact-webcam: Webcam capturelucide-react: Icons (Crop, X, Camera, Image)