Cutter是一款轻巧,灵活,可定制和可扩展的在线图像裁剪器,适用于台式机和移动设备。
还支持图像缩放,旋转,平移等等。
# NPM
$ npm i vue-cutter --save
# Bower
$ bower install vue-cutter --save
1.导入并注册切纸器组件。
// globally
import VueCutter from 'vue-cutter'
Vue.use(VueCutter)
// locally
import { VueCutter } from 'vue-cutter'
components: { VueCutter }
2.在应用程序中创建一个基本的图像裁剪器。
<template>
<div>
<vue-cutter
:container-bounding="options.bounding"
:src="options.src"
:output-type="options.outputType"
></vue-cutter>
</div>
</template>
export default {
name: "App",
data() {
return{
options: {
bounding: ['300px', '300px'],
src: '1.jpg',
outputType: 'png'
}
}
}
}
3.所有默认配置。
containerBounding: {
type: Array,
default: () => {
return ['0', '0']
}
},
src: {
type: [String, Blob, null, File],
default: ''
},
mode: {
type: String,
default: 'contain'
},
highQuality: {
type: Boolean,
default: false
},
// 0 - 1000;
enlarge: {
type: [Number, String],
default: 1
},
// output format
outputType: {
type: String,
default: 'jpeg'
},
// max image size
maxImgSize: {
type: [Number, String],
default: 2000
},
canImgMove: {
type: Boolean,
default: true
},
boxInImg: {
type: Boolean,
default: false
},
canScaleImg: {
type: Boolean,
default: true
},
canCropMove: {
type: Boolean,
default: true
},
cropBoxBounding: {
type: [String, Number],
default: 'auto'
},
fixed: {
type: [Array, String],
default: () => {
return null
}
},
canResizeCrop: {
type: Boolean,
default: true
},
cropBorder: {
type: String,
default: 'solid'
},
cropDividingLine: {
type: Boolean,
default: false
},
cropInfo: {
type: Boolean,
default: false
}
4.可用方法。
// 从本地添加一个图像
this.$refs.cutter.addLocalImage()
// 放大/缩小图像
this.$refs.cutter.relativeZoom(param)
// 旋转图像
this.$refs.cutter.rotateLeft()
this.$refs.cutter.rotateRight()
this.$refs.cutter.rotateClear()
// 得到轴
this.$refs.cutter.getImgAxis()
this.$refs.cutter.getCropAxis()
// base64数据
this.$refs.cutter.getBase64Data(funtion)
// blob数据
this.$refs.cutter.getBlobData(funtion)