Home

Awesome

<p align="center"><a href="https://advanced-cropper.github.io/vue-advanced-cropper/" target="_blank" rel="noopener noreferrer"><img width="133" src="https://github.com/advanced-cropper/vue-advanced-cropper/blob/master/example/readme/logo.svg?raw=true&timestamp=1608385818575" alt="Vue Advanced Cropper logo"></a></p> <br/> <p align="center"> <a href="https://npmcharts.com/compare/vue-advanced-cropper?minimal=true"><img src="https://img.shields.io/npm/dm/vue-advanced-cropper.svg?sanitize=true" alt="Downloads"></a> <a href="https://www.npmjs.com/package/vue-advanced-cropper"><img src="https://img.shields.io/npm/v/vue-advanced-cropper/vue-3.svg?sanitize=true" alt="Version"></a> <a href="https://www.npmjs.com/package/vue-advanced-cropper"><img src="https://img.shields.io/npm/v/vue-advanced-cropper/vue-2.svg?sanitize=true" alt="Version"></a> <a href="https://www.npmjs.com/package/vue-advanced-cropper"></a> <br> <a href="https://advanced-cropper.github.io/vue-advanced-cropper/" target="_blank" rel="noopener noreferrer">Documentation</a> / <a href="https://advanced-cropper.github.io/vue-advanced-cropper/guides/recipes.html" target="_blank" rel="noopener noreferrer">Examples</a> / <a href="https://codesandbox.io/s/vue-advanced-cropper-vue-3-yrxou?file=/src/App.vue" target="_blank" rel="noopener noreferrer">Sandbox</a> / <a href="https://codesandbox.io/s/vue-advanced-cropper-composition-api-5z0ww0?file=/src/App.vue" target="_blank" rel="noopener noreferrer">Sandbox + Composition API</a> </p> <h2 align="center"> </h2>

:fire: HEADS UP! You're currently looking at the branch for Vue 2. For the Vue 3 branch, please check out the vue-next branch.


Vue Advanced Cropper is the advanced library that allows you to create custom croppers suited for any website design. It means that you can change not only the cropper's appearance but also its behavior.

Features:

The codesandbox for mobile / desktop examples above.

Install

Vue 3.0

npm install --save vue-advanced-cropper
yarn add vue-advanced-cropper

Vue 2.0

npm install --save vue-advanced-cropper@vue-2
yarn add vue-advanced-cropper@vue-2

If you would like to use a CDN, please read the corresponding documentation section

Usage

import Vue from 'vue'
import { Cropper } from 'vue-advanced-cropper'
import 'vue-advanced-cropper/dist/style.css';

new Vue({
  el: '#app',
  data: {
    img: 'https://images.pexels.com/photos/226746/pexels-photo-226746.jpeg'
  },
  methods: {
    change({coordinates, canvas}) {
      console.log(coordinates, canvas)
    }
  },
  components: {
    Cropper
  }
})
<div id="app">
  <cropper
    class="cropper"
    :src="img"
    :stencil-props="{
      aspectRatio: 10/12
    }"
    @change="change"
  ></cropper>
</div>
/*
  You may need to set the limits for the cropper sizes or container sizes,
  otherwise, a cropping image will try to fill all available space
*/
.cropper {
  height: 600px;
  background: #DDD;
}

Cropper

PropTypeDescriptionDefault
srcStringThe cropping image (link / base64)
stencilComponentString, ObjectThe stencil componentRectangleStencil
stencilPropsObjectThe props for the stencil component{}
classStringThe optional class for the root cropper block
imageClassStringThe optional class for the cropping image
boundariesClassStringThe optional class for the area.
backgroundClassStringThe optional class for the background under the image
autoZoomBooleanEnable / disable transitionsfalse
transitionsBooleanEnable / disable auto zoomtrue
stencilSizeObject The size of the stencil in pixels
debounceString, NumberThe time before the change event will be emitted after changes (ms)500
canvasBooleanThe flag that indicates if canvas should be usedtrue
minWidthString, NumberThe minimum width of the stencil (percents)
minHeightString, NumberThe minimum height of the stencil (percents)
maxWidthString, NumberThe maximum width of the stencil (percents)
maxHeightString, NumberThe maximum height of the stencil (percents)
checkOrientationBooleanCheck if EXIF orientation should be checkedtrue
resizeImageBoolean, ObjectThe options for the image resizing (details)true
moveImageBoolean, ObjectThe options for the image moving (details)true
imageRestrictionStringSet restrictions for image position ('fill-area' 'fit-area', 'stencil', 'none')'fill-area'
defaultSizeObject, FunctionThe function that returns the default size of the stencil or objectcore.defaultSize
defaultPositionObject, FunctionThe function that returns the default position of the stencil or objectcore.defaultPosition
defaultBoundariesString, FunctionThe function that determines the boundaries size or string ('fill', 'fit')'fill'
sizeRestrictionsAlgorithmFunctionThe function that returns the restrictions object
EventDescription
changeInvoked on the changing of a stencil's position/size after mounting the component and on an image change
readyInvoked on the success of an image loading
errorInvoked on an error of an image loading

RectangleStencil

PropTypeDescriptionDefault
aspectRatioNumberThe aspect ratio
minAspectRatioNumberThe minimum aspect ratio
maxAspectRatioNumberThe maximum aspect ratio
classStringThe class for the root block of the stencil component
previewClassStringThe class for the preview component
movingClassStringThe class applied when the user drags the stencil
resizingClassStringThe class applied when the user resizes the stencil
boundingBoxClassStringThe class for the bounding box component
handlerComponentString,ObjectThe handler component
handlersObjectThe object of handlers that should be visible or hidden.
handlersClassesObjectThe object of custom handler classes
handlersWrappersClassesObjectThe object of custom handler wrapper classes
lineComponentString,ObjectThe handler component
linesObjectThe object of the lines that should be visible or hidden.
linesClassesObjectThe object of custom line classes
linesWrappersClassesObjectThe object of custom line wrapper classes

License

The source code of this library is licensed under the MIT license, and the documentation and photos belong to their respective owners.