Skip to content

Commit 21adbf1

Browse files
committed
add new dist files
2 parents 88e3abd + bc3bf46 commit 21adbf1

File tree

11 files changed

+108
-15
lines changed

11 files changed

+108
-15
lines changed

dist/crop.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default {
234234
},
235235
236236
rotateImage(degress) {
237-
const data = canvasHelper.rotate(this.originSrc, degress, (data, w, h) => {
237+
const data = canvasHelper.rotate2(this.originSrc, degress, (data, w, h) => {
238238
this.setImage(data, w, h);
239239
});
240240
//this.src = src;
@@ -275,7 +275,7 @@ export default {
275275
this.width = w;
276276
this.height = h;
277277
} else {
278-
if (r >= 1) {
278+
if (r >= this.cropCSS.width/this.cropCSS.height) {
279279
this.height = this.cropCSS.height;
280280
this.width = this.height * r;
281281
} else {

dist/lib/canvas-helper.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/props.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vue-core-image-upload.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<div class="g-core-image-corp-container" v-bind:id="'vciu-modal-' + formID" v-show="hasImage">
88
<crop ref="cropBox" :is-resize="resize && !crop" :ratio="cropRatio" :is-rotate="rotate"></crop>
99
<div class="info-aside">
10+
<p class="btn-groups rotate-groups" style="display:none">
11+
<button type="button" v-on:click="doRotate" class="btn btn-rotate">↺</button>
12+
<button type="button" v-on:click="doReverseRotate" class="btn btn-reverserotate">↻</button>
13+
</p>
1014
<p class="btn-groups" v-if="crop">
1115
<button type="button" v-on:click="doCrop" class="btn btn-upload">{{cropBtn.ok}}</button>
1216
<button type="button" v-on:click="cancel" class="btn btn-cancel">{{cropBtn.cancel}}</button>
@@ -133,7 +137,9 @@
133137
const cropBox = this.$refs.cropBox;
134138
pic.onload= function() {
135139
self.image.minProgress = self.minWidth / pic.naturalWidth;
136-
self.imgChangeRatio = cropBox.setImage(src, pic.naturalWidth, pic.naturalHeight);
140+
canvasHelper.init(src, (src) => {
141+
self.imgChangeRatio = cropBox.setImage(src, pic.naturalWidth, pic.naturalHeight);
142+
});
137143
}
138144
},
139145
@@ -142,6 +148,26 @@
142148
cropBox.resizeImage(progress);
143149
},
144150
151+
doRotate(e) {
152+
let self = this;
153+
const cropBox = this.$refs.cropBox;
154+
const targetImage = cropBox.getCropImage();
155+
this.data.comprose = 100 - this.compress;
156+
return canvasHelper.rotate(targetImage, 1, (src) => {
157+
self.__initImage(src)
158+
})
159+
},
160+
161+
doReverseRotate(e) {
162+
let self = this;
163+
const cropBox = this.$refs.cropBox;
164+
const targetImage = cropBox.getCropImage();
165+
this.data.comprose = 100 - this.compress;
166+
return canvasHelper.rotate(targetImage, -1, (src) => {
167+
self.__initImage(src)
168+
})
169+
},
170+
145171
doCrop(e) {
146172
this.__setData('crop');
147173
const cropBox = this.$refs.cropBox;
@@ -158,7 +184,7 @@
158184
},
159185
160186
doResize(e) {
161-
this.__setData('reszie');
187+
this.__setData('resize');
162188
const cropBox = this.$refs.cropBox;
163189
const upload = this.__setUpload(e.target);
164190
if (this.resize === 'local') {

index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-core-image-upload",
3-
"version": "2.3.6",
3+
"version": "2.3.7",
44
"description": "a vue plgin for image upload and crop",
55
"main": "dist/vue-core-image-upload.vue",
66
"dependencies": {

site/client/components/doc/en/CropImage.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
crop-ratio="1:1"
1616
crop="local"
1717
resize="local"
18+
:rotate="true"
1819
url="http://101.198.151.190/api/upload.php"
1920
@imageuploaded="crpoServerImageUploaded"
2021
:max-file-size="10485760"

src/crop.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export default {
234234
},
235235
236236
rotateImage(degress) {
237-
const data = canvasHelper.rotate(this.originSrc, degress, (data, w, h) => {
237+
const data = canvasHelper.rotate2(this.originSrc, degress, (data, w, h) => {
238238
this.setImage(data, w, h);
239239
});
240240
//this.src = src;
@@ -275,7 +275,7 @@ export default {
275275
this.width = w;
276276
this.height = h;
277277
} else {
278-
if (r >= 1) {
278+
if (r >= this.cropCSS.width/this.cropCSS.height) {
279279
this.height = this.cropCSS.height;
280280
this.width = this.height * r;
281281
} else {

src/lib/canvas-helper.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,47 @@ export default {
5858
}
5959
},
6060

61+
/**
62+
* init image for reset size and rotation
63+
**/
64+
init(src, callback) {
65+
let image = new Image();
66+
image.src = src;
67+
var self = this;
68+
image.onload = function() {
69+
var mimeType = self._getImageType(image.src);
70+
var cvs = self._getCanvas(image.naturalWidth, image.naturalHeight);
71+
var ctx = cvs.getContext("2d");
72+
ctx.drawImage(image, 0, 0);
73+
var newImageData = cvs.toDataURL(mimeType, 100);
74+
callback(newImageData);
75+
}
76+
},
77+
78+
/**
79+
* rotate image via canvas
80+
**/
81+
rotate(imageData, direction, callback) {
82+
let image = new Image();
83+
image.src = imageData.src;
84+
var self = this;
85+
image.onload = function() {
86+
var mimeType = self._getImageType(image.src);
87+
var cvs = self._getCanvas(image.naturalHeight, image.naturalWidth);
88+
var ctx = cvs.getContext("2d");
89+
if (direction == 1) {
90+
ctx.rotate(90 * Math.PI / 180);
91+
ctx.translate(0, -cvs.width);
92+
} else {
93+
ctx.rotate(-90 * Math.PI / 180);
94+
ctx.translate(-cvs.height, 0);
95+
}
96+
ctx.drawImage(image, 0, 0);
97+
var newImageData = cvs.toDataURL(mimeType, 100);
98+
callback(newImageData);
99+
}
100+
},
101+
61102
resize(image, options, callback) {
62103
const checkNumber = function(num) {
63104
return (typeof num === 'number');
@@ -73,7 +114,7 @@ export default {
73114
}
74115
},
75116

76-
rotate(src, degrees, callback) {
117+
rotate2(src, degrees, callback) {
77118
this._loadImage(src, (image) => {
78119
let w = image.naturalWidth;
79120
let h = image.naturalHeight;
@@ -102,7 +143,6 @@ export default {
102143
x = canvasWidth / 2 - w;
103144
y = canvasWidth / 2 - h;
104145
}
105-
106146
ctx.drawImage(image, x, y);
107147
const cvs2 = this._getCanvas(w, h);
108148
const ctx2 = cvs2.getContext('2d');

src/props.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
},
3838
rotate: {
3939
type: Boolean,
40-
default: true,
40+
default: false,
4141
},
4242
ResizeBtn: {
4343
type: Object,

0 commit comments

Comments
 (0)