1 | # vueShapeImg
|
2 |
|
3 | [![install size](https://packagephobia.now.sh/badge?p=vueshapeimg)](https://packagephobia.now.sh/result?p=vueshapeimg)
|
4 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/e05ad3648e3a437ca43a9d166c6b5bfa)](https://www.codacy.com/app/ArchieHurry/vueShapeImg)
|
5 |
|
6 | > Picture clipping component made with vue. vue编写的图片裁剪组件
|
7 |
|
8 | [If you like, please give me a star (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
9 |
|
10 | [如果你喜欢它,可以给我星星吗 (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
11 |
|
12 | ![Demonstration](http://www.bqmyweb.cn/vueshapeimg/1.3.1.gif)
|
13 |
|
14 | ## English <a href="https://github.com/ArchieHurry/vueShapeImg/blob/master/README_ZH.md">中文文档</a>
|
15 |
|
16 | ## [OnlineDemo](http://www.bqmyweb.cn/vueshapeimg/)
|
17 |
|
18 | ### How to use
|
19 |
|
20 | ``` bash
|
21 | import vueShapeImg from 'vueshapeimg'
|
22 | Vue.use(vueShapeImg)
|
23 |
|
24 | <vue-shape-img></vue-shape-img>
|
25 |
|
26 | ```
|
27 |
|
28 | ### vueShapeImg API Doc
|
29 |
|
30 | #### props
|
31 |
|
32 | |Parameters|Description|Type|Optional values|Default value|
|
33 | |----------|--------|----------|----------|----------|
|
34 | |useFrame|Clipping pictures using marquee boxes|Boolean|Y|false|
|
35 | |canResizeFrame|Whether the box can be scaled and moved|Boolean|Y|true|
|
36 | |initRange|Left,Top,Width and Height of box initialization|Array|Y|\[width\*0.25,height\*0.25,width\*0.5,height\*0.5\]|
|
37 | |height|-|Number|Y|500|
|
38 | |width|-|Number|Y|500|
|
39 | |timelyGetRange|Timely get user's select range|Boolean|Y|false|
|
40 | |timelyImageData|Timely converting pictures that capture the user's range of choice into imageData|Boolean|Y|false|
|
41 |
|
42 | ##### tips: You can't use imageData directly,show it in canvas putImageData
|
43 |
|
44 | #### methods
|
45 |
|
46 | |Method name|Description|Parameters|
|
47 | |----------|--------|----------|
|
48 | |rotate|Rotate the picture on canvas|deg(Arbitrary integer)|
|
49 | |setImgSrc|Use network picture. Pictures with different domain names are best not to be used|imgSrc(Picture links or Base64 files)|
|
50 | |fileClick|Use local picture|-|
|
51 | |showMask|Open the mask layer, select the area|-|
|
52 | |closeMask|Close the mask layer|-|
|
53 | |getRange|Get the scope of user selection|-|
|
54 | |setRange|Set the scope of user selection|\[left,top,width,height\]|
|
55 | |getImg|Get pictures of the range selected by the user|type('base64'/'blob'), imgType('image/jpeg' Or other image types),encoderOptions(0.00 - 1.00)|
|
56 |
|
57 | ##### tips: getImg -> imgType -> 'image/jpeg' can compress pictures better
|
58 |
|
59 | #### emit
|
60 |
|
61 | |emit name|Description
|
62 | |----------|--------|
|
63 | |imageDataChange|if props timelyImageData is true, this emit can return the imageData in timely|
|
64 | |rangeChange|if props timelyGetRange is true, this emit can return the range in timely|
|
65 | |error|error tips: -1(Picture format error), -2(Picture loading failed), -3(Pictures are cross-domain resources)|
|
66 |
|
67 | ##### tips: You can not use imageData directly,show it in canvas putImageData
|
68 |
|
69 | ### Example [OnlineDemo](http://www.bqmyweb.cn/vueshapeimg/)
|
70 |
|
71 | <pre><code>
|
72 | <template>
|
73 | <div id="app">
|
74 | <div style="width: 500px;">
|
75 | <button @click="$refs.vueShapeImg2.fileClick()">localImg</button>
|
76 | <button @click="$refs.vueShapeImg2.setImgSrc('http://www.bqmyweb.cn/vueshapeimg/demo.png')">networkImg</button>
|
77 | <button @click="$refs.vueShapeImg2.showMask()">startCrop</button>
|
78 | <button @click="$refs.vueShapeImg2.closeMask()">endCrop</button>
|
79 | <button @click="getImg2">getImg</button>
|
80 | <button @click="$refs.vueShapeImg2.setRange([200,200,200,200])">setRange</button>
|
81 | <button @click="$refs.vueShapeImg2.rotate(10)">rotate10</button>
|
82 | <button @click="$refs.vueShapeImg2.rotate(-10)">rotate-10</button>
|
83 | <p style="font-size: 18px;font-weight: bold;">useFrame:true</p>
|
84 | <vueShapeImg @error="imgError" :height="400" :width="400" :useFrame="true" :timelyImageData="true" @imageDataChange="putImg2" ref="vueShapeImg2"></vueShapeImg>
|
85 | <canvas id="canvas2"></canvas>
|
86 | </div>
|
87 | </div>
|
88 | </template>
|
89 |
|
90 | <script>
|
91 | export default {
|
92 | name: 'app',
|
93 | data () {
|
94 | return {
|
95 | canvas2: null,
|
96 | canvas2Ctx: null
|
97 | }
|
98 | },
|
99 | mounted () {
|
100 | this.canvas2 = document.getElementById('canvas2')
|
101 | this.canvas2Ctx = this.canvas2.getContext('2d')
|
102 | },
|
103 | methods: {
|
104 | putImg2 (imgData) {
|
105 | this.canvas2Ctx.clearRect(0, 0, 500, 500)
|
106 | let obj = this.$refs.vueShapeImg2.getRange()
|
107 | this.canvas2.width = obj.w
|
108 | this.canvas2.height = obj.h
|
109 | this.canvas2Ctx.putImageData(imgData, 0, 0)
|
110 | },
|
111 | getImg2 () {
|
112 | console.log(this.$refs.vueShapeImg2.getImg('base64', 'image/jpeg', 0.7))
|
113 | },
|
114 | imgError (error) {
|
115 | console.error(error)
|
116 | },
|
117 | }
|
118 | }
|
119 | </script>
|
120 | </code></pre>
|
121 |
|
122 | ### Browser support
|
123 |
|
124 | #### IE10+, chrome, firefox or other modern Browser
|
125 |
|
126 | ### Upgraded content
|
127 |
|
128 | #### 1.4.1 (2019-5-24 09:41:00)
|
129 |
|
130 | Fixed the problem of dragging the whole canvas when the mouseup event was triggered on the clipping box when moving the picture in the frame mode in IE browser.
|
131 |
|
132 | #### 1.3.4 (2019-5-15 15:17:51)
|
133 |
|
134 | Limit the range of input parameters of setRange function
|
135 |
|
136 | #### 1.3.2 (2019-5-15 11:23:55)
|
137 |
|
138 | Fixed the problem of calling the rotate function picture to return to the center of the canvas after moving the picture in frame mode
|
139 |
|
140 | #### 1.3.1 (2019-5-15 10:47:35)
|
141 |
|
142 | Adding image rotate function
|
143 |
|
144 | #### 1.3.0 (2019-5-13 17:25:10)
|
145 |
|
146 | Fixed the problem of onmouseup pollute caused by using multiple vueShapeImg on the same page and clipping box always exist
|
147 |
|
148 | Fixed cross-domain error multiple times triggered when using cross-domain images for cropping in normal mode
|
149 |
|
150 | [more version info](https://github.com/ArchieHurry/vueShapeImg/blob/master/version.md)
|