79bf3ada97f440a2782e417d1f0083a861a70a284080113c70df07bd7d6066eb30a27741365e392de79b8685ab37762e38eb5aa2db0447961dc00c6738723a 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. ## vue-cropper
  2. ### A simple picture clipping plugin for vue
  3. [preview](http://xyxiao.cn/vue-cropper/example/)
  4. [中文](https://github.com/xyxiao001/vue-cropper)
  5. ### Vue-cropper Related Articles Reference.。
  6. #### [vue全家桶开发管理后台—裁切图片](https://blog.csdn.net/qq_30632003/article/details/79639346)   作者: 麻球科技-菅双鹏
  7. #### [Vue-cropper 图片裁剪的基本原理](https://www.cnblogs.com/tugenhua0707/p/8859291.html) 作者: 龙恩0707
  8. ### vue-cropper communication.。
  9. ##### Any comments, or bugs or want to develop vue-cropper together, or want to develop other plugins together
  10. ![](https://qn-qn-kibey-static-cdn.app-echo.com/4C6FE9E2-3D06-402B-8F32-98B82BEBDD9F.png)
  11. # vue-cropper
  12. #### Install
  13. ```
  14. npm install vue-cropper
  15. yarn add vue-cropper
  16. ```
  17. #### Use
  18. ```
  19. views
  20. import { VueCropper } from "vue-cropper"
  21. components: {
  22. VueCropper,
  23. },
  24. main.js
  25. import VueCropper from "vue-cropper"
  26. Vue.use(VueCropper)
  27. cdn
  28. <script src="vuecropper.js"></script>
  29. Vue.use(window['vue-cropper'])
  30. <vueCropper
  31. ref="cropper"
  32. :img="option.img"
  33. :outputSize="option.size"
  34. :outputType="option.outputType"
  35. ></vueCropper>
  36. ```
  37. ### not use npm or webpack
  38. [online example](https://codepen.io/xyxiao001/pen/wxwKGz)
  39. ### serve render nuxt, control: ssr: false
  40. ```
  41. module.exports = {
  42. ...
  43. build: {
  44. vendor: [
  45. 'vue-cropper
  46. ...
  47. plugins: [
  48. { src: '~/plugins/vue-cropper', ssr: false }
  49. ]
  50. }
  51. }
  52. ```
  53. <table style="text-align: center">
  54. <thead>
  55. <tr>
  56. <td>name</td>
  57. <td>Features</td>
  58. <td>Detail</td>
  59. <td>value</td>
  60. </tr>
  61. </thead>
  62. <tbody>
  63. <tr>
  64. <td>img</td>
  65. <td>Picture address</td>
  66. <td>null</td>
  67. <td>url address || base64 || blob</td>
  68. </tr>
  69. <tr>
  70. <td>outputSize</td>
  71. <td>Crop the quality of the generated image</td>
  72. <td>1</td>
  73. <td>0.1 - 1</td>
  74. </tr>
  75. <tr>
  76. <td>outputType</td>
  77. <td>Crop the format of the generated image</td>
  78. <td>jpg (jpg need jpeg)</td>
  79. <td>jpeg || png || webp</td>
  80. </tr>
  81. <tr>
  82. <td>info</td>
  83. <td>Crop box size information</td>
  84. <td>true</td>
  85. <td>true || false</td>
  86. </tr>
  87. <tr>
  88. <td>canScale</td>
  89. <td>Whether the image allows the wheel to zoom</td>
  90. <td>true</td>
  91. <td>true || false</td>
  92. </tr>
  93. <tr>
  94. <td>autoCrop</td>
  95. <td>Whether to generate a screenshot box by default</td>
  96. <td>false</td>
  97. <td>true || false</td>
  98. </tr>
  99. <tr>
  100. <td>autoCropWidth</td>
  101. <td>Default generation of screenshot frame width</td>
  102. <td>parent's 80%</td>
  103. <td>0~max</td>
  104. </tr>
  105. <tr>
  106. <td>autoCropHeight</td>
  107. <td>Default generation of screenshot frame Height</td>
  108. <td>parent's 80%</td>
  109. <td>0~max</td>
  110. </tr>
  111. <tr>
  112. <td>fixed</td>
  113. <td>Whether to open the screenshot frame width and height fixed ratio</td>
  114. <td>true</td>
  115. <td>true | false</td>
  116. </tr>
  117. <tr>
  118. <td>fixedNumber</td>
  119. <td>The aspect ratio of the screenshot box</td>
  120. <td>[1 : 1]</td>
  121. <td>[width : height]</td>
  122. </tr>
  123. <tr>
  124. <td>full</td>
  125. <td>Screenshot of whether to output the original map scale</td>
  126. <td>false</td>
  127. <td>true | false</td>
  128. </tr>
  129. <tr>
  130. <td>fixedBox</td>
  131. <td>Fixed screenshot frame size is not allowed to change</td>
  132. <td>false</td>
  133. <td>true | false</td>
  134. </tr>
  135. <tr>
  136. <td>canMove</td>
  137. <td>Whether the uploaded image can be moved</td>
  138. <td>true</td>
  139. <td>true | false</td>
  140. </tr>
  141. <tr>
  142. <td>canMoveBox</td>
  143. <td>Can the screenshot box be dragged?</td>
  144. <td>true</td>
  145. <td>true | false</td>
  146. </tr>
  147. <tr>
  148. <td>original</td>
  149. <td>Upload images are rendered in raw scale</td>
  150. <td>false</td>
  151. <td>true | false</td>
  152. </tr>
  153. <tr>
  154. <td>centerBox</td>
  155. <td>Is the screenshot box restricted to the image?</td>
  156. <td>false</td>
  157. <td>true | false</td>
  158. </tr>
  159. <tr>
  160. <td>high</td>
  161. <td>Is it proportional to the dpi output of the device?</td>
  162. <td>true</td>
  163. <td>true | false</td>
  164. </tr>
  165. <tr>
  166. <td>infoTrue</td>
  167. <td>True to show the true output image width and height false show the width of the screenshot frame</td>
  168. <td>false</td>
  169. <td>true | false</td>
  170. </tr>
  171. <tr>
  172. <td>maxImgSize</td>
  173. <td>Limit the maximum width and height of the image</td>
  174. <td>2000</td>
  175. <td>0-max</td>
  176. </tr>
  177. <tr>
  178. <td>enlarge</td>
  179. <td>Picture output ratio multiplier based on screenshots</td>
  180. <td>1</td>
  181. <td>0-max(Don't be too big.)</td>
  182. </tr>
  183. <tr>
  184. <td>mode</td>
  185. <td>img render mode</td>
  186. <td>contain</td>
  187. <td>contain , cover, 100px, 100% auto</td>
  188. </tr>
  189. <!-- <tr>
  190. <td>limitMinSize</td>
  191. <td>crop mini width height</td>
  192. <td>10</td>
  193. <td>number, string, [number, number]</td>
  194. </tr> -->
  195. </tbody>
  196. </table>
  197. ### Built-in method Called by this.$refs.cropper
  198. ##### this.$refs.cropper.startCrop() Start the screenshot
  199. ##### this.$refs.cropper.stopCrop() Stop the screenshot
  200. ##### this.$refs.cropper.clearCrop() Clear screenshot
  201. ##### this.$refs.cropper.changeScale() Modify the image size. The positive number becomes larger. The negative number becomes smaller.
  202. ##### this.$refs.cropper.getImgAxis() Get the image based on the container's coordinate points
  203. ##### this.$refs.cropper.getCropAxis() Get the screenshot box based on the container's coordinate point
  204. ##### this.$refs.cropper.goAutoCrop Automatically generate screenshot box functions
  205. ##### this.$refs.cropper.rotateRight() Rotate 90 degrees to the right
  206. ##### this.$refs.cropper.rotateLeft() Rotate 90 degrees to the left
  207. #### Image loaded callback imgLoad returns the result success, error
  208. #### Get screenshot information
  209. this.$refs.cropper.cropW screenshot frame width
  210. this.$refs.cropper.cropH screenshot frame height
  211. ``` js
  212. // Get the base64 data of the screenshot
  213. this.$refs.cropper.getCropData((data) => {
  214.    // do something
  215.    Console.log(data)
  216. })
  217. // Get the screenshot of the blob data
  218. this.$refs.cropper.getCropBlob((data) => {
  219.    // do something
  220.    Console.log(data)
  221. })
  222. ### Preview
  223. ``` html
  224. @realTime="realTime"
  225. // Real time preview function
  226. realTime (data) {
  227. this.previews = data
  228. }
  229. <div class="show-preview" :style="{'width': previews.w + 'px', 'height': previews.h + 'px', 'overflow': 'hidden',
  230. 'margin': '5px'}">
  231. <div :style="previews.div">
  232. <img :src="option.img" :style="previews.img">
  233. </div>
  234. </div>
  235. =
  236. ```
  237. #### Image Move Callback Function @imgMoving
  238. ```
  239. data type
  240. {
  241. moving: true, // moving ismove
  242. axis: {
  243. x1: 1, // Upper left corner
  244. x2: 1,// Upper right corner
  245. y1: 1,// Lower left corner
  246. y2: 1 // Bottom right corner
  247. }
  248. }
  249. ```
  250. #### Screenshot box move callback function @cropMoving
  251. ```
  252. data type
  253. {
  254. moving: true, // moving 是否在移动
  255. axis: {
  256. x1: 1, // Upper left corner
  257. x2: 1,// Upper right corner
  258. y1: 1,// Lower left corner
  259. y2: 1 // Bottom right corner
  260. }
  261. }
  262. ```
  263. ## Update log
  264. ### 0.54
  265. ` ` ` `
  266. Remove log information
  267. Fix PC Safari low version
  268. ` ` ` `
  269. ### 0.53
  270. ` ` ` `
  271. Because chrome 81 kernel and IOS 13.5 fix the image rotation bug
  272. The plug-in will not process rotation by default in the new version of browser, and it will be processed automatically in the lower version of browser
  273. https://www.chromestatus.com/feature/6313474512650240
  274. ### 0.52
  275. ```
  276. Recall the attribute of the minimum bullet box. There is a bug in the judgment of the dragging coordinate of the bullet box
  277. ```
  278. ## 0.51
  279. `` `
  280. Update the minimum attributes of the crop box, limit the minimum area, can pass more than 1 numbers and strings, limit the length and width are so large, can also pass arrays [90,90]
  281. limitMinSize: [Number, Array, String]
  282. `` `
  283. ### 0.50
  284. Support picture empty
  285. Fix ie11 ie10 not working
  286. Fix the bug that URL.createObjectURL is not destroyed after creation
  287. Add screenshot box to modify trigger event
  288. this. $ emit ('change-crop-size', {
  289.    width: this.cropW,
  290.    height: this.cropH
  291. })
  292. ### 0.49
  293. Fix the default event of the scroll wheel
  294. Fix the issue of event trigger in html static file
  295. ### 0.48
  296. Fix display bug of mode attribute contain and cover
  297. Fix the problem of cross domain display of base64 pictures under ios
  298. ### 0.47
  299. Fix the problem that does not trigger preview for the first time
  300. New image rendering mode function
  301. ### 0.46
  302. Fix image rotation bug
  303. Fix some bugs displayed
  304. ### 0.45
  305. Add multiples using enlarge
  306. You can output clipping boxes and other proportional images.
  307. Thank you for your contribution from [https://github.com/hzsrc].
  308. Add preview box to various proportions, and restore image screenshots decimal problem.
  309. ### 0.44
  310. 修复引入方式的问题
  311. ```
  312. Repairing the way of introduction
  313. import { VueCropper } from vue-cropper
  314. components: {
  315. VueCropper,
  316. },
  317. main.js
  318. import VueCropper from vue-cropper
  319. Vue.use(vueCropper)
  320. cdn
  321. <script src="vuecropper.js"></script>
  322. Vue.use(window['vue-cropper'])
  323. ```
  324. ### V0.43
  325. Peel off EXIF's dependency library, add exfi-min.js to reduce code size 45.9k = 37k
  326. Build upgrade webpack4 upgrade
  327. ` ` ` ` ` ` ` ` ` '.
  328. Add Vue install method = "npm: Vue.use (VueCropper) web: Vue.use (window['vue-cropper'])"
  329. ` ` ` ` ` ` ` ` ` '.
  330. ### V0.42
  331. Repair screenshots because of the problem of removing decimal points.
  332. ### V0.41
  333. Repair boundary problem of screenshots
  334. ### V0.40
  335. The way to repair orientation
  336. Thanks for the contribution of [Felipe Mengatto] (https://github.com/felipemengatto).
  337. ### v0.40
  338. fix orientation handel
  339. Thanks for the contribution of [Felipe Mengatto] (https://github.com/felipemengatto)
  340. ### v0.39
  341. Fix problems caused by different orientation values
  342. Thanks for the contribution of [Felipe Mengatto] (https://github.com/felipemengatto)
  343. ### v0.38
  344. ```
  345. Modify coordinate feedback problem
  346. ```
  347. ### v0.37
  348. ```
  349. Fix screenshot of centerBox out of 1px issue
  350. Add screenshot Image move trigger event
  351. ```
  352. ### v0.36
  353. ```
  354. Fix rotation automatically generates screenshot box error
  355. Modify autocrop to dynamically generate screenshot boxes
  356. ```
  357. ### v0.35
  358. ```
  359. Fix other images without compression issues
  360. ```
  361. ### v0.34
  362. ``` provides a solution for mobile crashes
  363. Modify maxImgSize to 2000
  364. ```
  365. ### v0.33
  366. ``` provides a solution for mobile crashes
  367. maxImgSize limits the maximum width and height of the image to 2000px by default.
  368. ```
  369. ### v0.32
  370. ```
  371. Add screenshot box information display
  372. infoTrue true to show the true output image width and height false show the width of the screenshot box
  373. ```
  374. ### v0.30
  375. ```
  376. Added image coordinate function this.$refs.cropper.getImgAxis()
  377. Added the capture box coordinate function this.$refs.cropper.getCropAxis()
  378. Added compatibility with HD devices high
  379. Added screenshot box to limit the function within the image centerbox
  380. Added automatic generation of screenshot box function this.$refs.cropper.goAutoCrop
  381. ```
  382. ### v0.29
  383. Added callback for image loading imgLoad returns result success, error
  384. ### v0.28
  385. Fix the screenshot box fixed The screenshot box will affect the original image movement Zoom
  386. ### v0.27
  387. Mouse scaling problem optimization
  388. Img max-width style optimization
  389. New attribute
  390. CanMove can move pictures by default is yes
  391. CanMoveBox move the screenshot box by default?
  392. Original Whether to render in the original scale of the image Default is No
  393. ### v0.26
  394. Fix Firefox browser mouse zoom problem
  395. ### v0.25
  396. Fix image may not show
  397. ### v0.24
  398. Fix ios photo rotation Screenshot problem Add auto fix image Screenshot preview code change, modify default upload image as blob preview
  399. ``` html
  400. realTime (data) {
  401.   this.previews = data
  402. }
  403. <div class="show-preview" :style="{'width': previews.w + 'px', 'height': previews.h + 'px', 'overflow': 'hidden',
  404.     'margin': '5px'}">
  405.   <div :style="previews.div">
  406.     <img :src="previews.url" :style="previews.img">
  407.   </div>
  408. </div>
  409. ```
  410. ### v0.23
  411. Small optimization
  412. ### v0.22
  413.  New modified image size function called by this.$refs.cropper.changeScale
  414. ### v0.21
  415. Added fixed screenshot frame size fiexdBox (Note: It is best to use the automatic generation of screenshot box)
  416. ### v0.20
  417. Added output original image scale screenshot props name full, fix zoom image too large sensitivity problem
  418. ### v0.19
  419. Add image rotation to fix mac wheel over-sensitive
  420. ``` js
  421. this.$refs.cropper.rotateRight() // Rotate 90 degrees to the right
  422. this.$refs.cropper.rotateLeft() // Rotate 90 degrees to the left
  423. ```
  424. ### v0.18
  425. Fix default build screenshot box over container error
  426. ### v0.17
  427. Fix blob data acquisition error
  428. ### v0.15
  429. Add mobile phone gesture zoom
  430. ```
  431. canScale: true
  432. ```
  433. ### v0.13
  434. Add preview
  435. ``` html
  436. @realTime="realTime"
  437. // Real time preview function
  438. realTime (data) {
  439.   this.previews = data
  440. }
  441. <div class="show-preview" :style="{'width': previews.w + 'px', 'height': previews.h + 'px', 'overflow': 'hidden',
  442.     'margin': '5px'}">
  443.   <div :style="previews.div">
  444.     <img :src="option.img" :style="previews.img">
  445.   </div>
  446. </div>
  447. ```