|
| 1 | +<template> |
| 2 | + <div class="components"> |
| 3 | + <h3>Crop Image</h3> |
| 4 | + <p>Set <code>crop</code> value to help you crop the image. </p> |
| 5 | + <p class="warnning"> if you setted the crop props, you can not upload multiple files.</p> |
| 6 | + <p>You have two values to select,<strong>local crop:<code>local</code></strong>or<strong>server-side crop: <code>server</code></strong>.</p> |
| 7 | + <h4>Local Crop</h4> |
| 8 | + <p><code>crop="local"</code> The Browser will crop the image via canvas API and send the cropped image to the server.</p> |
| 9 | + <div class="center"> |
| 10 | + <div class="user"> |
| 11 | + <img class="avatar" :src="src"/> |
| 12 | + </div> |
| 13 | + <vue-core-image-upload |
| 14 | + crop-ratio="1:1" |
| 15 | + :class="['btn', 'btn-primary']" |
| 16 | + crop="local" |
| 17 | + url="http://101.198.151.190/api/upload.php" |
| 18 | + extensions="png,jpeg,jpg" |
| 19 | + text="Crop Image" |
| 20 | + compress="20" |
| 21 | + @imageuploaded="crpoServerImageUploaded"> |
| 22 | + </vue-core-image-upload> |
| 23 | + </div> |
| 24 | + <h4>Server-side crop</h4> |
| 25 | + <p><code>crop="server"</code> means the bwowser will send the original image to the server and post the cropped data below to the server:</p> |
| 26 | + <img style="width:480px;" src="http://img1.vued.vanthink.cn/vuedbb5d2173fa90af576b66f7077a87bfdb.jpeg" /> |
| 27 | + <p>Each filed introduce:</p> |
| 28 | + <ul> |
| 29 | + <li><code>toCropImgX</code>: The x-axis distance between the crop area and the image</li> |
| 30 | + <li><code>toCropImgY</code>: The y-axis distance between the crop area and the image</li> |
| 31 | + <li><code>toCropImgW</code>: The width of crop area</li> |
| 32 | + <li><code>toCropImgH</code>: The height of crop area</li> |
| 33 | + <li><code>maxWidth</code>: The maximum width of the crop image</li> |
| 34 | + <li><code>maxHeight</code>: The maximum height of the crop image</li> |
| 35 | + </ul> |
| 36 | + <h4>Code example</h4> |
| 37 | + <p>上传图片后可以看到裁剪的参数</p> |
| 38 | + <div class="center"> |
| 39 | + <div class="user"> |
| 40 | + <img class="avatar" :src="cropSrc"/> |
| 41 | + </div> |
| 42 | + <vue-core-image-upload |
| 43 | + crop-ratio="1:1" |
| 44 | + :class="['btn', 'btn-primary']" |
| 45 | + crop="server" |
| 46 | + url="http://101.198.151.190/api/crop.php" |
| 47 | + extensions="png,gif,jpeg,jpg" |
| 48 | + text="Crop Image" |
| 49 | + @imageuploaded="crpoServerImageUploaded"> |
| 50 | + </vue-core-image-upload> |
| 51 | + </div> |
| 52 | + <table class="m-table bordered" style="width:100%;"> |
| 53 | + <thead> |
| 54 | + <tr> |
| 55 | + <th>H</th> |
| 56 | + <th>W</th> |
| 57 | + <th>X</th> |
| 58 | + <th>Y</th> |
| 59 | + </tr> |
| 60 | + </thead> |
| 61 | + <tbody> |
| 62 | + <tr> |
| 63 | + <td>{{cropArgs.toCropImgH}}</td> |
| 64 | + <td>{{cropArgs.toCropImgW}}</td> |
| 65 | + <td>{{cropArgs.toCropImgX}}</td> |
| 66 | + <td>{{cropArgs.toCropImgY}}</td> |
| 67 | + </tr> |
| 68 | + </tbody> |
| 69 | + </table> |
| 70 | + <pre v-highlightjs><code class="HTML"><vue-core-image-upload |
| 71 | + crop-ratio="1:1" |
| 72 | + :class="['btn', 'btn-primary']" |
| 73 | + crop="server" |
| 74 | + url="http://101.198.151.190/api/crop.php" |
| 75 | + extensions="png,gif,jpeg,jpg" |
| 76 | + text="Crop Image" |
| 77 | + @imageuploaded="crpoServerImageUploaded"> |
| 78 | +</vue-core-image-upload> |
| 79 | + |
| 80 | + </code></pre> |
| 81 | + <a href>View Code Source</a> |
| 82 | + </div> |
| 83 | +</template> |
| 84 | + |
| 85 | +<script> |
| 86 | +import VueCoreImageUpload from '../../../../src/vue-core-image-upload.vue' |
| 87 | +export default { |
| 88 | + components: { |
| 89 | + VueCoreImageUpload |
| 90 | + }, |
| 91 | + data() { |
| 92 | + return { |
| 93 | + src: 'http://img1.vued.vanthink.cn/vued7553a09a5d5209ebd00a48264394b7f3.png', |
| 94 | + cropSrc: 'http://img1.vued.vanthink.cn/vued7553a09a5d5209ebd00a48264394b7f3.png', |
| 95 | + cropArgs: { |
| 96 | + toCropImgH: '?', |
| 97 | + toCropImgW: '?', |
| 98 | + toCropImgX: '?', |
| 99 | + toCropImgY: '?' |
| 100 | + } |
| 101 | + }; |
| 102 | + }, |
| 103 | +
|
| 104 | + methods: { |
| 105 | + cropLocalImageUploaded(res) { |
| 106 | + this.src = res.data.src; |
| 107 | + }, |
| 108 | + crpoServerImageUploaded(res) { |
| 109 | + if (res.errcode === 0) { |
| 110 | + if (res.data.src) { |
| 111 | + this.src = res.data.src; |
| 112 | + return; |
| 113 | + } |
| 114 | + this.name = res.data.name; |
| 115 | + this.cropArgs = { |
| 116 | + toCropImgH: parseInt(res.data.post.toCropImgH), |
| 117 | + toCropImgW: parseInt(res.data.post.toCropImgW), |
| 118 | + toCropImgX: parseInt(res.data.post.toCropImgX), |
| 119 | + toCropImgY: parseInt(res.data.post.toCropImgY) |
| 120 | + } |
| 121 | + this.cropSrc = 'http://img1.vued.vanthink.cn/vued41b900045d6d44f3b32e06049621b415.png'; |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | +}; |
| 126 | +
|
| 127 | +</script> |
0 commit comments