1 | # vueShapeImg
|
2 |
|
3 | [If you like, please give me a star (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
4 |
|
5 | [如果你喜欢它,可以给我星星吗 (๑•̀ㅂ•́)و✧](https://github.com/ArchieHurry/vueShapeImg)
|
6 |
|
7 | ![Demonstration](http://www.bqmyweb.cn/vueshapeimg/1.3.1.gif)
|
8 |
|
9 | ## <a name="english">English</a> <a href="#中文文档">中文文档</a>
|
10 |
|
11 | > An image resizer made by vue
|
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
|
67 |
|
68 | #### in HTML:
|
69 |
|
70 | <pre><code>
|
71 | <div style="width: 500px;margin: 20px auto">
|
72 | <button @click="$refs.vueShapeImg.fileClick()" >localImage</button>
|
73 | <button @click="$refs.vueShapeImg._main('https://i.loli.net/2019/05/05/5cce957e23c2c.jpg')">networkImage</button>
|
74 | <button @click="$refs.vueShapeImg.showMask()" >startCropper</button>
|
75 | <button @click="$refs.vueShapeImg.closeMask()" >closeCropper</button>
|
76 | <button @click="getImage" >getImage</button>
|
77 | </div>
|
78 | <vueShapeImg :height="400" :width="400" :timelyGetRange="true" :timelyImageData="true"
|
79 | @imageDataChange="imageDataChange" @rangeChange="rangeChange" ref="vueShapeImg"></vueShapeImg>
|
80 | </code></pre>
|
81 |
|
82 | #### in Methods:
|
83 |
|
84 | <pre><code>
|
85 | rangeChange (obj) {
|
86 | console.log(obj)
|
87 | },
|
88 | imageDataChange (data) {
|
89 | console.log(data)
|
90 | },
|
91 | getImage () {
|
92 | console.log(this.$refs.vueShapeImg.getImg('base64', 'image/png',0.2))
|
93 | },
|
94 | </code></pre>
|
95 |
|
96 | ### Browser support
|
97 |
|
98 | ##### IE10+, chrome, firefox or other modern Browser
|
99 |
|
100 |
|
101 | ## <a name="中文文档">中文文档</a> <a href="#english">English</a>
|
102 |
|
103 | > 使用vue编写的图片裁剪组件
|
104 |
|
105 | ## [在线例子](http://www.bqmyweb.cn/vueshapeimg/)
|
106 |
|
107 | ### 怎样使用
|
108 |
|
109 | ``` bash
|
110 | import vueShapeImg from 'vueshapeimg'
|
111 | Vue.use(vueShapeImg)
|
112 |
|
113 | <vue-shape-img></vue-shape-img>
|
114 |
|
115 | ```
|
116 |
|
117 | ### 接口文档
|
118 |
|
119 | #### props
|
120 |
|
121 | | 名称 | 描述 | 类型 | 可选参数 | 默认值 |
|
122 | |---------- |-------- |---------- |---------- |---------- |
|
123 | |useFrame|是否使用选框裁剪图片| Boolean | Y | false |
|
124 | |canResizeFrame|选框是否可以缩放| Boolean | Y | true |
|
125 | |initRange|数组,依次为左边距,上边距,宽,高| Array | Y | [width * 0.25, height * 0.25, width * 0.5 ,height * 0.5] |
|
126 | |height |- |Number |Y |500 |
|
127 | |width |- |Number |Y |500 |
|
128 | |timelyGetRange |是否及时的获取用户选择的区域 |Boolean |Y |false |
|
129 | |timelyImageData |是否及时的返回用户选择的图像区域|Boolean |Y |false |
|
130 |
|
131 | ##### 注意: 用户选择的图像区域不能直接使用,使用canvas的pitImageData可以展示
|
132 |
|
133 | #### methods
|
134 |
|
135 | |方法名 | 描述 | 参数 |
|
136 | |---------- |-------- |---------- |
|
137 | |rotate|旋转canvas上的图片|任意整数|
|
138 | |setImgSrc|如果使用的是网络图片,那么不同域名的图片最好不要使用 |imgSrc(任意可以被img标签加载的资源)|
|
139 | |fileClick|使用本地图片|-|
|
140 | |showMask|展开遮罩层,用户选择区域|-|
|
141 | |closeMask|关闭遮罩层|-|
|
142 | |getRange|获取用户选择的区域|-|
|
143 | |setRange|设置用户选框的大小| [left,top,width,height] |
|
144 | |getImg|获取用户选择的区域|type('base64'/'blob'), imgType('image/png' 或者其他任意的web可支持的图片格式),encoderOptions(图片质量默认0.92,可选0.00 - 1.00) |
|
145 |
|
146 | ##### tips: getImg -> imgType -> 'image/jpeg' 可以更好的压缩图片
|
147 |
|
148 | #### emit
|
149 |
|
150 | | emit name | Description
|
151 | |---------- |-------- |
|
152 | |imageDataChange|如果timelyImageData为true,那么会及时返回用户选择区域的图像,图像是imageData,img不能直接展示|
|
153 | |rangeChange|如果timelyGetRange为true,那么会及时返回用户选择的区域|
|
154 | |error|错误提示: -1(图片格式错误), -2(图片加载失败), -3(图片为跨域资源) |
|
155 |
|
156 | ##### tips: imageDataChange返回的值可以通过 canvas的putImageData展示
|
157 |
|
158 | ### 举例
|
159 |
|
160 | #### html里面:
|
161 |
|
162 | <pre><code>
|
163 | <div style="width: 500px;margin: 20px auto">
|
164 | <button @click="$refs.vueShapeImg.fileClick()" >localImage</button>
|
165 | <button @click="$refs.vueShapeImg._main('https://i.loli.net/2019/05/05/5cce957e23c2c.jpg')">networkImage</button>
|
166 | <button @click="$refs.vueShapeImg.showMask()" >startCropper</button>
|
167 | <button @click="$refs.vueShapeImg.closeMask()" >closeCropper</button>
|
168 | <button @click="getImage" >getImage</button>
|
169 | </div>
|
170 | <vueShapeImg :height="400" :width="400" :timelyGetRange="true" :timelyImageData="true"
|
171 | @imageDataChange="imageDataChange" @rangeChange="rangeChange" ref="vueShapeImg"></vueShapeImg>
|
172 | </code></pre>
|
173 |
|
174 | #### 方法里面:
|
175 |
|
176 | <pre><code>
|
177 | rangeChange (obj) {
|
178 | console.log(obj)
|
179 | },
|
180 | imageDataChange (data) {
|
181 | console.log(data)
|
182 | },
|
183 | getImage () {
|
184 | console.log(this.$refs.vueShapeImg.getImg('base64', 'image/png',0.2))
|
185 | },
|
186 | </code></pre>
|
187 |
|
188 | ### 浏览器支持情况
|
189 |
|
190 | ##### IE10+, chrome, firefox 和其他现代浏览器
|
191 |
|
192 |
|
193 | ### Upgraded content(升级的内容)
|
194 |
|
195 | #### 1.3.1(2019-5-15 10:47:35)
|
196 |
|
197 | - Adding image rotation function
|
198 |
|
199 | 添加了图片旋转功能
|
200 |
|
201 | #### 1.3.0(2019-5-13 17:25:10)
|
202 |
|
203 | - Fixed the problem of onmouseup pollute caused by using multiple vueShapeImg on the same page and clipping box always exist
|
204 |
|
205 | 修复在同一页面中使用多个vueShapeImg导致onmouseup污染,裁剪框一直存在的问题
|
206 |
|
207 | - Fixed cross-domain error multiple times triggered when using cross-domain images for cropping in normal mode
|
208 |
|
209 | 修复在普通模式下使用跨域图片进行裁剪时多次报错的问题
|
210 |
|
211 | #### 1.2.9(2019-5-13 17:05:41)
|
212 |
|
213 | - Fixed the problem of using timelyGetRange to report cross-domain errors in normal mode
|
214 |
|
215 | 修复了普通模式下使用timelyGetRange报跨域错误的问题
|
216 |
|
217 | #### 1.2.8(2019-5-13 16:21:55)
|
218 |
|
219 | - Fixed the problem that timelyGetRange did not trigger when zooming and moving the underlying image in useFrame mode.
|
220 |
|
221 | 修复了在useFrame模式下缩放和移动底层图片,timelyGetRange 不触发的问题。
|
222 |
|
223 | #### 1.2.6(2019-5-13 15:41:56)
|
224 |
|
225 | - Fixed cross-domain image resource contamination canvas, resulting in subsequent images can not be tailored locally.
|
226 |
|
227 | 修复了跨域的图片资源污染canvas,造成后续的图片无法本地裁剪的问题。
|
228 |
|
229 | - Added \$emit ('error'), processing picture format does not support, picture loading failure, cross-domain picture problems.
|
230 |
|
231 | 增添了 $emit('error'),处理图片格式不支持,图片加载失败,图片跨域问题。
|