A image crop plug-in for Vue,you can use it to rotate、zoom images and cut any size
- For IE9+,MSEdge,Chrome,Firefox
- Your can config it in line or modal
- rotate、zoom
- Cut to scale
- Crop original image
- Crop remote pictures
https://ihtmlcss.com/demo/dist/#/croptool
Github:https://github.com/acccccccb/vue-img-cutter
码云:https://gitee.com/GLUESTICK/vue-img-cutter
If this project is helpful to you, please give me a star :)
- Install
npm install vue-img-cutter --save-dev
- Import ImgCutter.vue:
import ImgCutter from 'vue-img-cutter'
export default {
components:{
ImgCutter
},
...
}
- Write the code in template:
<ImgCutter v-on:cutDown="cutDown"></ImgCutter>
- Solt
<ImgCutter v-on:cutDown="cutDown">
<button slot="open">Select image</button>
</ImgCutter>
- This method to be compatible with IE9,it can also be used to crop cross domain images
- Create an object(name,src,
width and heightare required).
- this.$refs.imgCutterModal.handleOpen(The Object).
// The object like this.
let obj = {
name:'1.jpg',//Image name
src:'http://url/1.jpg',// Image url
//width:200,//Image width remove in 2.1.9+
//height:200,//Image height remove in 2.1.9+
}
ForIE9:function(){
// First you need create object have name,src.
// Then trigger handleOpen(obj) and deliver the obj.
this.$refs.imgCutterModal.handleOpen({
name:"image.jpg",
src:"http://imageServ.com/image.jpg",
});
}
Attribute | Effect | Type | Require | Default |
---|---|---|---|---|
isModal | Is modal | Boolean | No | true |
showChooseBtn | Show select btn | Boolean | No | true |
lockScroll | Lock scroll when modal is show | Boolean | No | true |
label | Button text | String | No | 选择图片 |
boxWidth | Tool width | Number | No | 800 |
boxHeight | Tool height | Number | No | 400 |
cutWidth | Selection box width | Number | No | 200 |
cutHeight | Selection box height | Number | No | 200 |
tool | Show toolbar | Boolean | No | true |
toolBgc | Toolbar background color | String(eg: "#fff") | No | #fff |
sizeChange | Allow change size | Boolean | No | true |
moveAble | Allow change position | Boolean | No | true |
originalGraph | Crop original image | Boolean | No | false |
crossOrigin | Is cross origin image | Boolean | No | false |
crossOriginHeader | Set cross origin header | String | No | '' |
rate | Aspect ratio | String(eg: "4:3") | No | - |
WatermarkText | Watermark Text | String | No | '' |
WatermarkTextFont | Watermark font size | String | No | '12px Sans-serif' |
WatermarkTextColor | Watermark font color | String | No | '#fff' |
WatermarkTextX | Watermark position x | Number | No | 0.95 |
WatermarkTextY | Watermark position y | Number | No | 0.95 |
smallToUpload | If choose image size less then defined Size,return file. sizeChange must be false | Boolean | No | false |
saveCutPosition | Save last cut position and size | Boolean | No | false |
scaleAble | Allow scale image | Boolean | No | true |
Attribute | Effect | Type | Require | Return |
---|---|---|---|---|
cutDown | Cut down image | Function | Yes | Object |
error | Throw error | Function | No | Error object |
onChooseImg | ChooseImg | Function | No | Object |
onPrintImg | Print image to canvas | Function | No | Object |
onClearAll | Clear all | Function | No | null |
Slot name | Effect |
---|---|
open | Choose btn |
openImgCutter | Choose btn |
choose | Choose btn(in tool) |
cancel | Cancel btn |
confirm | Confirm btn |
ratio | Toolbar ratio |
scaleReset | Toolbar reset scale |
turnLeft | Toolbar turn left |
turnRight | Toolbar turn right |
reset | Toolbar reset |
flipHorizontal | Toolbar flip horizontal |
flipVertically | Toolbar flip vertically |
Attribute | Description |
---|---|
fileName | File name |
file | File(Some versions of IE is not support) |
blob | Blob(Some versions of IE is not support) |
dataURL | dataURL |
- Original picture
- Mirror
- New features:
- 1.saveCutPosition:Save last cut position and size
- 2.scaleAble:Able/Disable scale image
- Crop original image not need imageObj.width and imageObj.height
- New features:smallToUpload, If choose image size less then defined Size,return file. sizeChange must be false. #20
- Fix bug:#21 cropPicture() missed params
- Add new hook function:onClearAll,onPrintImg,onChooseImg
- Fix bug:Button add attrib type=button
- Fix bug:Width display error
- Fix bug:When no choose Image,you also can get an empty image,now you will get an error message in error callback
- Fix bug:When rate < 0 the result image size error;
- New features:flip horizontal,flip vertically,Watermark
- Add slot:ratio,scaleReset,turnLeft,turnRight,reset,flipHorizontal,flipVertically
- Add english documents
- Add new attribute:originalGraph,originalGraph
- Fix bug: Inline mode can not scale image.
- Fix bug: Constituency overflow.
- UI optimization.
- Show version
- New slot:choose/cancel/confirm
- New attribute:toolBgc
- Fix bug: Constituency overflow.
- Fix bug:Remote image in the wrong place.
- Fix bug:An error occurred when click cancel btn in IE.
- Fix bug:Error loading remote picture will be correctly handle.
- Fix bug:An error occurred when not choose any image.
- Update readme.md
- Update crop remote pictures method. eg:this.$refs['yourComponent'].handleOpen(imgObj),imgObj must include(name,src,width,height)
- Fix bug: Inline mode can not scale image.
- New attribute: crossOrigin,crossOriginHeader
- New attribute: error,It can catch error.
- New attribute:isModal/showChooseBtn/lockScroll
- For IE9+,MSEdge,chrome,firefox
- UI optimization.
- For IE8+,MSEdge,chrome,firefox
- New attribute:moveAble,sizeChange
- Fix bug:File is not return.
- For IE11+,MSEdge,Chrome,Firefox
- Result add file.
- Fix bug:Reload pages when first click select image btn.
- UI optimization.
- UI optimization.
- UI optimization.