(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.

Related Posts

Simple-and-Modern-Multi-Level-Sidebar-Menu-on-Bootstrap-4

[Offcanvas] Simple and Modern Multi-Level Sidebar Menu on Bootstrap 4

The multi-level sidebar menu is simple and fast on Bootstrap. So you must be aware of how to use Bootstrap itself. This plugin is fast, responsive, multi-level,…

vanilla-js-carousel

Flip Sliding Carousel Gallery Made Of CSS And Vanilla JS

Vanilla JS Carousel is a JavaScript Slider plugin for navigating objects in a 3D space just like Cover Flow. Getting started Clone or download the repo. Open…

bootstrap-5-dark-theme

Dark & Light Switch Mode Toggle for Bootstrap 5

Switching to dark mode is done by toggling HTML tags that include -dark or -light as a category. It is made by manipulating the DOM with JavaScript. The text color also changes depending…

vuejs-dialog-plugin

Vuejs Lightweight Prompt Based On Promise And Confirm Dialog

VUEJS DIALOG PLUGIN is a lightweight, promise-based, prompt, and dialog-based alert. Important updates The dialog will always be resolved by an object. (ie a callback to continue…

browser-alert-confirm-dialog-alert4html-js

Insert HTML Into Your Browser Alert & Confirm Dialog | alert4html.js

alert4html.js is a JavaScript library that enables you to insert HTML directly into your browser alerts while simulating Chrome alerts as well. alert4html.js is an alternative to…

Lightweight-Flexbox-Carousel-Plugin

Simple and Lightweight Flexbox Carousel Plugin With JavaScript | flexCarousel.js

Flexbox Responsive Slider – flexCarousel.js plugin is a simple and lightweight plug-in from Flexbox carousel ES6 JavaScript. An unofficial fork by Slick Carousel. Flex Carousel is a…