Cropper.js is a powerful, pure JavaScript library for image cropping that provides extensive functionalities including moving, zooming, rotating, and scaling images directly within web browsers. The current stable version is 2.1.1, with the project demonstrating active maintenance through consistent patch and minor releases, indicating ongoing development and bug fixes. A key differentiator is its standalone nature, operating without external dependencies like jQuery, making it lightweight and suitable for modern JavaScript ecosystems. It offers a highly configurable and extensible API, allowing developers to tailor the cropping experience precisely. The library ships with comprehensive TypeScript declaration files, ensuring excellent developer experience in TypeScript projects, and supports both UMD and ESM module formats for broad compatibility across different environments.
npm install cropperjsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Cropper.js with an image element, including essential CSS and basic configuration options like aspect ratio and view mode, and logs crop events.
Explicitly set `rotatable: true`, `scalable: true`, `skewable: true`, or `translatable: true` in the Cropper options if these features are desired.
Update your code to use the `dynamic` property instead of `linked` for CropperSelection configurations.
Ensure that `cropperjs/dist/cropper.css` is correctly imported in your JavaScript entry point (`import 'cropperjs/dist/cropper.css';`) or linked in your HTML (`<link rel="stylesheet" href="node_modules/cropperjs/dist/cropper.css">`).
Set the `crossorigin="anonymous"` attribute on your `<img>` tag. Additionally, ensure the server hosting the image is configured with appropriate CORS headers (e.g., `Access-Control-Allow-Origin: *` or your specific origin).
Add `import 'cropperjs/dist/cropper.css';` to your main JavaScript/TypeScript file or ensure the CSS is included in your HTML.
Add the `crossorigin="anonymous"` attribute to your `<img>` tag. Verify the image server is configured to send `Access-Control-Allow-Origin` headers that permit requests from your domain.
For CommonJS, use `const Cropper = require('cropperjs').default;`. For modern JavaScript modules, stick to `import Cropper from 'cropperjs';` and ensure your bundler (e.g., Webpack, Rollup) or TypeScript configuration (`esModuleInterop: true`) handles default interop correctly.Inspect your CSS for conflicting rules, particularly `box-sizing` on elements within or around the cropper. Ensure no other scripts are interfering with mouse events. Check if upgrading to a newer Cropper.js version (e.g., v2.1.0 addressed shadow DOM event target issues) resolves the problem.
No dependency data recorded yet.