1.0.5 • Published 5 years ago

cutterjs v1.0.5

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

Installation

CLI

npm install cutterjs -S

Browser

<script src="https://unpkg.com/cutterjs@1.0.5/dist/cutterjs.min.js"></script>

Quick Start

// init
let cutter = new Cutter({
    imageSrc: './images/bg.jpeg',
    containerEl: '.wrap',
    scalable: false,
    zoomable: false,
    rotatable: false,
    cutBoxResizable: false,
    scaleEl: '#scale',
    zoomEl: '#zoom',
    cutEl: '#cut',
    rotateEl: '#rotate',
    outputType: 'jpeg',
    onRender() {
        console.log('渲染成功')
    },
    onScale(config) {
        console.log(config, 'has scaled')
    },
    onZoom(config) {
        console.log(config, 'has zoomed')
    },
    onCut(url) {
        console.log(url, 'image base64 url')
        document.querySelector('#image').src = url
    }
})

// get cropped image's base64 url
let imagUrl = cutter.cutImage()

Params

ParamTyperequiredDefaultNotes
imageSrcStringtrue''A image's source that will be cropped.
containerElStringtrue''A area that operate cropping a image. It can be a class name or a id.
scalableBooleanfalsetrueIf true, the image can be scaled.
zoomableBooleanfalsetrueIf true, the image can be zoomed.
ratatableBooleanfalsetrueIf true, the image can be rotated.
cutBoxResizableBooleanfalsetrueIf true, the size of the cropped image can be resized.
scaleElStringfalse''A dom that can trigger scaling the image.If the value of scalable is true, it is required.
zoomElStringfalse''A dom that can trigger zooming the image.If the value of zoomable is true, it is required.
rotateElStringfalse''A dom that can trigger rotating the image.If the value of ratatable is true, it is required.
cutElStringfalse''A dom that can trigger cropping the image.
minCutWidthNumberfalse16The minimum width of the cropped image's size.
cutWidthNumberfalse200The width of the cropped image's It must be bigger than the value of minCutWidth.
minCutHeightNumberfalse16The minimum height of the cropped image's size.
cutHeightNumberfalse200The heigth of the cropped image's size. It must be bigger than the value of minCutHeight.
maxScaleRatioNumberfalse3The maximum scale ratio of the image.
maxZoomRatioNumberfalse3The maximum zoom ratio of the image.
onRenderFunctionfalsenullThe callback after rendering successfully.
onCutFunctionfalsenullThe callback after cropping. It will return base64 url of the cropped image.
onScaleFunctionfalsenullThe callback after scaling. It will return all config.
onZoomFunctionfalsenullThe callback after zooming. It will return all config.

Methods

  • cutImage(imageUrl) cut the image and get the image's base64 url
    let cutter = new Cutter(
        ...
    )
    let imageUrl = cutter.cutImage()