1 | # vueShapeImg
|
2 |
|
3 | > Picture clipping component made with vue
|
4 |
|
5 | [If you like, please give me a star (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
6 |
|
7 | [如果你喜欢它,可以给我星星吗 (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
8 |
|
9 | ![Demonstration](http://www.bqmyweb.cn/vueshapeimg/1.3.1.gif)
|
10 |
|
11 | ## <a name="english">English</a> <a href="#中文文档">中文文档</a>
|
12 |
|
13 | ## [OnlineDemo](http://www.bqmyweb.cn/vueshapeimg/)
|
14 |
|
15 | ### How to use
|
16 |
|
17 | ``` bash
|
18 | import vueShapeImg from 'vueshapeimg'
|
19 | Vue.use(vueShapeImg)
|
20 |
|
21 | <vue-shape-img></vue-shape-img>
|
22 |
|
23 | ```
|
24 |
|
25 | ### vueShapeImg API Doc
|
26 |
|
27 | #### props
|
28 |
|
29 | | Parameters | Description | Type | Optional values | Default value |
|
30 | |---------- |-------- |---------- |---------- |---------- |
|
31 | |useFrame|Clipping pictures using marquee boxes| Boolean | Y | false |
|
32 | |canResizeFrame|Whether the box can be scaled and moved| Boolean | Y | true |
|
33 | |initRange|Left,Top,Width and Height of box initialization| Array | Y | [width * 0.25, height * 0.25, width * 0.5 ,height * 0.5] |
|
34 | |height |- |Number |Y |500 |
|
35 | |width |- |Number |Y |500 |
|
36 | |timelyGetRange |Timely get user's select range |Boolean |Y |false |
|
37 | |timelyImageData |Timely converting pictures that capture the user's range of choice into imageData |Boolean |Y |false |
|
38 |
|
39 | ##### tips: You can't use imageData directly,show it in canvas putImageData
|
40 |
|
41 | #### methods
|
42 |
|
43 | | Method name | Description | Parameters |
|
44 | |---------- |-------- |---------- |
|
45 | |rotate|Rotate the picture on canvas|deg(Arbitrary integer) |
|
46 | |setImgSrc|Use network picture. Pictures with different domain names are best not to be used |imgSrc(Picture links or Base64 files)|
|
47 | |fileClick|Use local picture|-|
|
48 | |showMask|Open the mask layer, select the area|-|
|
49 | |closeMask|Close the mask layer|-|
|
50 | |getRange|Get the scope of user selection|-|
|
51 | |setRange|Set the scope of user selection| [left,top,width,height] |
|
52 | |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) |
|
53 |
|
54 | ##### tips: getImg -> imgType -> 'image/jpeg' can compress pictures better.
|
55 |
|
56 | #### emit
|
57 |
|
58 | | emit name | Description
|
59 | |---------- |-------- |
|
60 | |imageDataChange|if props timelyImageData is true, this emit can return the imageData in timely|
|
61 | |rangeChange|if props timelyGetRange is true, this emit can return the range in timely|
|
62 | |error|error tips: -1(Picture format error), -2(Picture loading failed), -3(Pictures are cross-domain resources) |
|
63 |
|
64 | ##### tips: You can't use imageData directly,show it in canvas putImageData
|
65 |
|
66 | ### Example [OnlineDemo](http://www.bqmyweb.cn/vueshapeimg/)
|
67 | <pre><code>
|
68 | <template>
|
69 | <div id="app">
|
70 | <div style="width: 500px;display: inline-block;float: left">
|
71 | <button @click="$refs.vueShapeImg2.fileClick()">localImg</button>
|
72 | <button @click="$refs.vueShapeImg2.setImgSrc('http://www.bqmyweb.cn/vueshapeimg/demo.png')">networkImg</button>
|
73 | <button @click="$refs.vueShapeImg2.showMask()">startCrop</button>
|
74 | <button @click="$refs.vueShapeImg2.closeMask()">endCrop</button>
|
75 | <button @click="getImg2">getImg</button>
|
76 | <button @click="$refs.vueShapeImg2.setRange([200,200,200,200])">setRange</button>
|
77 | <button @click="$refs.vueShapeImg2.rotate(10)">rotate10</button>
|
78 | <button @click="$refs.vueShapeImg2.rotate(-10)">rotate-10</button>
|
79 | <p style="font-size: 18px;font-weight: bold;">useFrame:true</p>
|
80 | <vueShapeImg @error="imgError" :height="400" :width="400" :useFrame="true" :timelyImageData="true" @imageDataChange="putImg2" ref="vueShapeImg2"></vueShapeImg>
|
81 | <canvas style="margin-left: 50px" id="canvas2"></canvas>
|
82 | </div>
|
83 | <div style="clear: both"></div>
|
84 | </div>
|
85 | </template>
|
86 |
|
87 | <script>
|
88 | export default {
|
89 | name: 'app',
|
90 | data () {
|
91 | return {
|
92 | canvas2: null,
|
93 | canvas2Ctx: null
|
94 | }
|
95 | },
|
96 | mounted () {
|
97 | this.canvas2 = document.getElementById('canvas2')
|
98 | this.canvas2Ctx = this.canvas2.getContext('2d')
|
99 | },
|
100 | methods: {
|
101 | putImg2 (imgData) {
|
102 | this.canvas2Ctx.clearRect(0, 0, 500, 500)
|
103 | let obj = this.$refs.vueShapeImg2.getRange()
|
104 | this.canvas2.width = obj.w
|
105 | this.canvas2.height = obj.h
|
106 | this.canvas2Ctx.putImageData(imgData, 0, 0)
|
107 | },
|
108 | getImg2 () {
|
109 | console.log(this.$refs.vueShapeImg2.getImg('base64', 'image/jpeg', 0.7))
|
110 | },
|
111 | imgError (error) {
|
112 | console.error(error)
|
113 | },
|
114 | }
|
115 | }
|
116 | </script>
|
117 | </code></pre>
|
118 |
|
119 |
|
120 | ### Browser support
|
121 |
|
122 | ##### IE10+, chrome, firefox or other modern Browser
|
123 |
|
124 |
|
125 | ## <a name="中文文档">中文文档</a> <a href="#english">English</a>
|
126 |
|
127 | > 使用vue编写的图片裁剪组件
|
128 |
|
129 | ## [在线例子](http://www.bqmyweb.cn/vueshapeimg/)
|
130 |
|
131 | ### 怎样使用
|
132 |
|
133 | ``` bash
|
134 | import vueShapeImg from 'vueshapeimg'
|
135 | Vue.use(vueShapeImg)
|
136 |
|
137 | <vue-shape-img></vue-shape-img>
|
138 |
|
139 | ```
|
140 |
|
141 | ### 接口文档
|
142 |
|
143 | #### props
|
144 |
|
145 | | 名称 | 描述 | 类型 | 可选参数 | 默认值 |
|
146 | |---------- |-------- |---------- |---------- |---------- |
|
147 | |useFrame|是否使用选框裁剪图片| Boolean | Y | false |
|
148 | |canResizeFrame|选框是否可以缩放| Boolean | Y | true |
|
149 | |initRange|数组,依次为左边距,上边距,宽,高| Array | Y | [width * 0.25, height * 0.25, width * 0.5 ,height * 0.5] |
|
150 | |height |- |Number |Y |500 |
|
151 | |width |- |Number |Y |500 |
|
152 | |timelyGetRange |是否及时的获取用户选择的区域 |Boolean |Y |false |
|
153 | |timelyImageData |是否及时的返回用户选择的图像区域|Boolean |Y |false |
|
154 |
|
155 | ##### 注意: 用户选择的图像区域不能直接使用,使用canvas的pitImageData可以展示
|
156 |
|
157 | #### methods
|
158 |
|
159 | |方法名 | 描述 | 参数 |
|
160 | |---------- |-------- |---------- |
|
161 | |rotate|旋转canvas上的图片|任意整数|
|
162 | |setImgSrc|如果使用的是网络图片,那么不同域名的图片最好不要使用 |imgSrc(任意可以被img标签加载的资源)|
|
163 | |fileClick|使用本地图片|-|
|
164 | |showMask|展开遮罩层,用户选择区域|-|
|
165 | |closeMask|关闭遮罩层|-|
|
166 | |getRange|获取用户选择的区域|-|
|
167 | |setRange|设置用户选框的大小| [left,top,width,height] |
|
168 | |getImg|获取用户选择的区域|type('base64'/'blob'), imgType('image/png' 或者其他任意的web可支持的图片格式),encoderOptions(图片质量默认0.92,可选0.00 - 1.00) |
|
169 |
|
170 | ##### tips: getImg -> imgType -> 'image/jpeg' 可以更好的压缩图片
|
171 |
|
172 | #### emit
|
173 |
|
174 | | emit name | Description
|
175 | |---------- |-------- |
|
176 | |imageDataChange|如果timelyImageData为true,那么会及时返回用户选择区域的图像,图像是imageData,img不能直接展示|
|
177 | |rangeChange|如果timelyGetRange为true,那么会及时返回用户选择的区域|
|
178 | |error|错误提示: -1(图片格式错误), -2(图片加载失败), -3(图片为跨域资源) |
|
179 |
|
180 | ##### tips: imageDataChange返回的值可以通过 canvas的putImageData展示
|
181 |
|
182 | ### 举例 [在线例子](http://www.bqmyweb.cn/vueshapeimg/)
|
183 | <pre><code>
|
184 | <template>
|
185 | <div id="app">
|
186 | <div style="width: 500px;display: inline-block;float: left">
|
187 | <button @click="$refs.vueShapeImg2.fileClick()">localImg</button>
|
188 | <button @click="$refs.vueShapeImg2.setImgSrc('http://www.bqmyweb.cn/vueshapeimg/demo.png')">networkImg</button>
|
189 | <button @click="$refs.vueShapeImg2.showMask()">startCrop</button>
|
190 | <button @click="$refs.vueShapeImg2.closeMask()">endCrop</button>
|
191 | <button @click="getImg2">getImg</button>
|
192 | <button @click="$refs.vueShapeImg2.setRange([200,200,200,200])">setRange</button>
|
193 | <button @click="$refs.vueShapeImg2.rotate(10)">rotate10</button>
|
194 | <button @click="$refs.vueShapeImg2.rotate(-10)">rotate-10</button>
|
195 | <p style="font-size: 18px;font-weight: bold;">useFrame:true</p>
|
196 | <vueShapeImg @error="imgError" :height="400" :width="400" :useFrame="true" :timelyImageData="true" @imageDataChange="putImg2" ref="vueShapeImg2"></vueShapeImg>
|
197 | <canvas style="margin-left: 50px" id="canvas2"></canvas>
|
198 | </div>
|
199 | <div style="clear: both"></div>
|
200 | </div>
|
201 | </template>
|
202 |
|
203 | <script>
|
204 | export default {
|
205 | name: 'app',
|
206 | data () {
|
207 | return {
|
208 | canvas2: null,
|
209 | canvas2Ctx: null
|
210 | }
|
211 | },
|
212 | mounted () {
|
213 | this.canvas2 = document.getElementById('canvas2')
|
214 | this.canvas2Ctx = this.canvas2.getContext('2d')
|
215 | },
|
216 | methods: {
|
217 | putImg2 (imgData) {
|
218 | this.canvas2Ctx.clearRect(0, 0, 500, 500)
|
219 | let obj = this.$refs.vueShapeImg2.getRange()
|
220 | this.canvas2.width = obj.w
|
221 | this.canvas2.height = obj.h
|
222 | this.canvas2Ctx.putImageData(imgData, 0, 0)
|
223 | },
|
224 | getImg2 () {
|
225 | console.log(this.$refs.vueShapeImg2.getImg('base64', 'image/jpeg', 0.7))
|
226 | },
|
227 | imgError (error) {
|
228 | console.error(error)
|
229 | },
|
230 | }
|
231 | }
|
232 | </script>
|
233 |
|
234 | </code></pre>
|
235 |
|
236 |
|
237 | ### 浏览器支持情况
|
238 |
|
239 | ##### IE10+, chrome, firefox 和其他现代浏览器
|
240 |
|
241 | ### Upgraded content(升级的内容)
|
242 |
|
243 | #### 1.3.4(2019-5-15 15:17:51)
|
244 |
|
245 | - Limit the range of input parameters of setRange function
|
246 |
|
247 | 限制了setRange 函数的输入参数范围
|
248 |
|
249 | #### 1.3.2(2019-5-15 11:23:55)
|
250 |
|
251 | - Fixed the problem of calling the rotate function picture to return to the center of the canvas after moving the picture in frame mode
|
252 |
|
253 | 修复框架模式下图片移动后调用旋转函数图片返回画布中心的问题
|
254 |
|
255 | #### 1.3.1(2019-5-15 10:47:35)
|
256 |
|
257 | - Adding image rotate function
|
258 |
|
259 | 添加了图片旋转功能
|
260 |
|
261 | #### 1.3.0(2019-5-13 17:25:10)
|
262 |
|
263 | - Fixed the problem of onmouseup pollute caused by using multiple vueShapeImg on the same page and clipping box always exist
|
264 |
|
265 | 修复在同一页面中使用多个vueShapeImg导致onmouseup污染,裁剪框一直存在的问题
|
266 |
|
267 | - Fixed cross-domain error multiple times triggered when using cross-domain images for cropping in normal mode
|
268 |
|
269 | 修复在普通模式下使用跨域图片进行裁剪时多次报错的问题
|
270 |
|
271 | #### 1.2.9(2019-5-13 17:05:41)
|
272 |
|
273 | - Fixed the problem of using timelyGetRange to report cross-domain errors in normal mode
|
274 |
|
275 | 修复了普通模式下使用timelyGetRange报跨域错误的问题
|
276 |
|
277 | [more version info(更多版本信息)](https://github.com/ArchieHurry/vueShapeImg/blob/master/version.md)
|