Croppie Image Cropper
Croppie is a lightweight, pure JavaScript image cropping library designed for easy integration into web applications. As of April 2026, the current stable version is 2.6.5. Its release cadence is irregular, with patches and minor feature updates released periodically, often addressing bug fixes and introducing new capabilities like blob/canvas output or improved accessibility. Key differentiators include its small footprint, lack of external dependencies (historically not requiring jQuery, although a breaking change related to jQuery events was noted in v2.6.0), keyboard navigation support (since v2.2.0), and flexible output options including base64, raw canvas, and file blobs. A significant consideration is the project's explicit statement regarding the absence of automated tests, which implies a higher risk of regressions or unexpected behavior in new releases, as acknowledged in the v2.5.0 release notes.
Common errors
-
Uncaught ReferenceError: Croppie is not defined
cause The Croppie script file (`croppie.js` or `croppie.min.js`) was not loaded or was not available in the current JavaScript scope.fixEnsure the `<script>` tag for `croppie.js` is correctly placed in your HTML (typically before your application script) or that `require('croppie')` is used in a CommonJS environment that correctly bundles the library. -
SecurityError: The operation is insecure.
cause Attempting to read pixel data from a canvas that contains images loaded from a different origin without proper CORS (Cross-Origin Resource Sharing) headers.fixVerify that all images bound to Croppie are either served from the same domain as your web application, or that the image server is configured to send `Access-Control-Allow-Origin` headers that permit cross-origin access. -
Page scrolls unexpectedly when attempting to zoom the image with the mouse wheel within Croppie.
cause Croppie's default behavior captures mouse wheel events for zooming, which can override page scrolling.fixInitialize Croppie with the option `mouseWheelZoom: 'ctrl'` to require the Ctrl key to be pressed for mouse wheel zooming, allowing normal page scrolling otherwise. -
Cropped image result is blank, corrupted, or has incorrect dimensions.
cause This can occur due to various reasons, including invalid image URLs, image loading failures, incorrect Croppie configuration (e.g., `viewport` or `boundary` too small), or issues specific to certain browsers/versions (e.g., IE11/Safari issues fixed in v2.4.0).fixCheck the console for image loading errors. Ensure the image URL is valid and accessible. Verify `viewport` and `boundary` dimensions. If using an older version, update Croppie to at least v2.4.0 for improved browser compatibility and result reliability.
Warnings
- breaking The jQuery update event was changed or removed in v2.6.0, affecting applications that relied on Croppie's integration with jQuery's event system.
- gotcha Croppie explicitly states it lacks automated tests, increasing the risk of regressions or unexpected behavior in new releases. The v2.5.0 release notes specifically acknowledged potential breakage.
- gotcha By default, Croppie's mouse wheel zoom can capture scroll events, preventing normal page scrolling. This can be a disruptive user experience.
- gotcha Previous versions (before 2.4.0) had known issues with `enforceBoundary: false` and correctly retrieving results, particularly in Safari and Internet Explorer 11.
- gotcha Attempting to retrieve cropped image data (e.g., as canvas or blob) from an image loaded from a different origin will lead to browser security 'CORS' errors.
Install
-
npm install croppie -
yarn add croppie -
pnpm add croppie
Imports
- Croppie
import { Croppie } from 'croppie';<link rel="stylesheet" href="croppie.css" /><script src="croppie.js"></script>
- Croppie
import Croppie from 'croppie';
const Croppie = require('croppie'); - CroppieOptions
import type { CroppieOptions } from 'croppie';
Quickstart
<!-- HTML: Ensure croppie.css is linked -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.5/croppie.min.css">
<div id="croppie-demo" style="width: 300px; height: 300px;"></div>
<button id="get-result">Get Cropped Image</button>
<!-- JavaScript: Ensure croppie.js is loaded -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/croppie/2.6.5/croppie.min.js"></script>
<script>
const el = document.getElementById('croppie-demo');
const croppie = new Croppie(el, {
viewport: { width: 150, height: 150, type: 'circle' },
boundary: { width: 200, height: 200 },
showZoomer: true,
enableResize: true,
mouseWheelZoom: 'ctrl' // Only zoom when Ctrl key is pressed
});
croppie.bind({
url: 'https://images.unsplash.com/photo-1549880338-65ddcdfd017b?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MTR8fGxpZ2h0aW5nfGVufDB8fDB8fHww',
zoom: 0
}).then(() => {
console.log('Croppie bind complete with default image.');
});
document.getElementById('get-result').addEventListener('click', () => {
croppie.result({
type: 'base64',
size: 'viewport',
format: 'jpeg',
quality: 0.8
}).then(function (resp) {
const img = new Image();
img.src = resp;
img.style.maxWidth = '100%';
document.body.appendChild(document.createElement('br'));
document.body.appendChild(document.createTextNode('Cropped Image:'));
document.body.appendChild(img);
console.log('Cropped image (base64):', resp.substring(0, 50) + '...');
});
});
</script>