Press "Enter" to skip to content

(base64) Pure JavaScript Image Cropping Functionality To Your Web | js-cropper

js-cropper is a quick and easy way to add image cropping functionality to your web application without dependencies.

image cropper js, cropper js download, cropper js example code, cropper js set width height, javascript crop image before upload

Features

  • Promise API
  • Supports Touch Events
  • Multiple callbacks
  • No dependencies (pure JavaScript code)
  • Excellentย Browser support
  • Based on canvas technology
  • Available Zooming (Setting/Resetting/UI input)
  • Exports cropped image in Base64
  • Gets position/zoom in JSON data
  • Sets position/zoom from JSON data
  • Dynamically changing dimensions of cropping area via available public methods
  • Loads image by URL
  • and many others…

How to make use of it:

1. Install js-cropper.js library.

# Yarn
$ yarn add js-cropper
# NPM
$ npm install js-cropper --save

2. Import js-cropper.js and js-cropper.css into the project.

// ES 6
import Cropper from 'js-cropper';
// CommonJS:
const Cropper = require('js-cropper');

3. Create a container element for the cropping area.

<div id="crop"></div>

4. Configure the image trimmer with the default settings.

const cropper = new Cropper();
cropper.render("#crop");

5. Upload the photo you want to crop.

cropper.loadImage("/path/to/image.jpg").then(function (crop) {
  console.info("Image is ready to crop.");
});

6. Export the cropped image in Base64.

cropper.getCroppedImage()

7. Default options and callback functions.

const cropper = new Cropper({
      width: 560,
      height: 340,
      onInit: function (crop) {},
      onChange: function(crop) {}
});

8. More API methods.

const cropper = new Cropper({
      // options here
});
// Changes Image Crop width.
cropper.setWidth(width);
// Changes Image Crop height.
cropper.setHeight(height); 
// Sets zoom level. 
cropper.setZoom(zoom);
// Gets data in JSON
cropper.getData();
// Sets data from JSON
cropper.setData();
// Reset
cropper.reset();

touch-enabled image cropper, js-cropper Plugin/Github


See Demo And Download

Official Website(denis-kalinichenko): Click Here

This superior jQuery/javascript plugin is developed by denis-kalinichenko. For extra advanced usage, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *