Skip to content

Commit

Permalink
Merge pull request #755 from xyxiao001/fix_xxy_exif_version
Browse files Browse the repository at this point in the history
feat: update 0.6.3 && 1.1.0
  • Loading branch information
xyxiao001 authored Sep 1, 2023
2 parents 7b77f0d + 1a6d926 commit b3067ba
Show file tree
Hide file tree
Showing 16 changed files with 83 additions and 65 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 更新日志
## vue3.x组件更新日志
### v1.1.0
- 修复 exif 读取图片出错的情况
- 新增 @imgLoadError方法返回对应错误
### v1.0.9
- 新增 fillCover, 导出图片背景颜色
### v1.0.8
Expand Down Expand Up @@ -29,6 +32,9 @@
- 支持 `vue3` 版本

## vue2.x组件更新日志
### v0.6.3
- 修复 exif 读取图片出错的情况
- 新增 @imgLoadError方法返回对应错误
### v0.6.2
- 新增 fillCover, 导出图片背景颜色
### v0.6.1
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions docs/vue2.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,17 @@
img: "https://avatars2.githubusercontent.com/u/15681693?s=460&v=4"
},
{
img: "http://cdn.xyxiao.cn/Landscape_1.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_2f07496a52314c3e024eaafaba73dd35.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_2.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/mosaic-legacy_2e7480001384708367aa1.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_3.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-i-0813_80f34c63344d44c292dacf4608c7b258.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_4.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_48b61ee1b6b34fe945246cd1ccc4243d.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_1.jpg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_2.jpg"
}
],
option: {
img: "https://avatars2.githubusercontent.com/u/15681693?s=460&v=4",
Expand Down
14 changes: 4 additions & 10 deletions docs/vue3.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,23 +308,17 @@
img: "https://avatars2.githubusercontent.com/u/15681693?s=460&v=4"
},
{
img: "http://cdn.xyxiao.cn/Landscape_1.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_2f07496a52314c3e024eaafaba73dd35.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_2.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/mosaic-legacy_2e7480001384708367aa1.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_3.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-i-0813_80f34c63344d44c292dacf4608c7b258.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_4.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_48b61ee1b6b34fe945246cd1ccc4243d.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_1.jpg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_2.jpg"
}
],
option: {
img: "https://avatars2.githubusercontent.com/u/15681693?s=460&v=4",
Expand Down
2 changes: 1 addition & 1 deletion next/dist/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 22 additions & 14 deletions next/dist/vue-cropper.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ const Y = {};
Y.getData = (t) => new Promise((e, i) => {
let s = {};
I(t).then((r) => {
s.arrayBuffer = r, s.orientation = k(r), e(s);
s.arrayBuffer = r;
try {
s.orientation = T(r);
} catch {
s.orientation = -1;
}
e(s);
}).catch((r) => {
i(r);
});
Expand Down Expand Up @@ -41,19 +47,19 @@ function E(t, e) {
(this.status == 200 || this.status === 0) && e(this.response);
}, i.send();
}
function L(t) {
t = t.replace(/^data\:([^\;]+)\;base64,/gmi, "");
for (var e = atob(t), i = e.length, s = new ArrayBuffer(i), r = new Uint8Array(s), o = 0; o < i; o++)
r[o] = e.charCodeAt(o);
return s;
function L(t, e) {
e = e || t.match(/^data\:([^\;]+)\;base64,/mi)[1] || "", t = t.replace(/^data\:([^\;]+)\;base64,/gmi, "");
for (var i = atob(t), s = i.length, r = new ArrayBuffer(s), o = new Uint16Array(r), h = 0; h < s; h++)
o[h] = i.charCodeAt(h);
return r;
}
function T(t, e, i) {
function k(t, e, i) {
var s = "", r;
for (r = e, i += e; r < i; r++)
s += String.fromCharCode(t.getUint8(r));
return s;
}
function k(t) {
function T(t) {
var e = new DataView(t), i = e.byteLength, s, r, o, h, n, l, c, a, p, f;
if (e.getUint8(0) === 255 && e.getUint8(1) === 216)
for (p = 2; p < i; ) {
Expand All @@ -63,7 +69,7 @@ function k(t) {
}
p++;
}
if (c && (r = c + 4, o = c + 10, T(e, r, 4) === "Exif" && (l = e.getUint16(o), n = l === 18761, (n || l === 19789) && e.getUint16(o + 2, n) === 42 && (h = e.getUint32(o + 4, n), h >= 8 && (a = o + h)))), a) {
if (c && (r = c + 4, o = c + 10, k(e, r, 4) === "Exif" && (l = e.getUint16(o), n = l === 18761, (n || l === 19789) && e.getUint16(o + 2, n) === 42 && (h = e.getUint32(o + 4, n), h >= 8 && (a = o + h)))), a) {
for (i = e.getUint16(a, n), f = 0; f < i; f++)
if (p = a + f * 12 + 2, e.getUint16(p, n) === 274) {
p += 8, s = e.getUint16(p, n);
Expand Down Expand Up @@ -400,7 +406,7 @@ const N = (t, e) => {
let t = new Image();
if (t.onload = () => {
if (this.img === "")
return this.$emit("img-load", "error"), !1;
return this.$emit("img-load", new Error("图片不能为空")), !1;
let i = t.width, s = t.height;
Y.getData(t).then((r) => {
this.orientation = r.orientation || 1;
Expand All @@ -410,9 +416,11 @@ const N = (t, e) => {
return;
}
i > o && (s = s / i * o, i = o), s > o && (i = i / s * o, s = o), this.checkOrientationImage(t, this.orientation, i, s);
}).catch((r) => {
this.$emit("img-load", "error"), this.$emit("img-load-error", r);
});
}, t.onerror = () => {
this.$emit("img-load", "error");
}, t.onerror = (i) => {
this.$emit("img-load", "error"), this.$emit("img-load-error", i);
}, this.img.substr(0, 4) !== "data" && (t.crossOrigin = ""), this.isIE) {
var e = new XMLHttpRequest();
e.onload = function() {
Expand Down Expand Up @@ -1059,10 +1067,10 @@ function U(t, e, i, s, r, o) {
])
], 544);
}
const W = /* @__PURE__ */ N(A, [["render", U], ["__scopeId", "data-v-18751258"]]), F = function(t) {
const W = /* @__PURE__ */ N(A, [["render", U], ["__scopeId", "data-v-69939069"]]), F = function(t) {
t.component("VueCropper", W);
}, j = {
version: "1.0.9",
version: "1.1.0",
install: F,
VueCropper: W
};
Expand Down
6 changes: 3 additions & 3 deletions next/dist/vue-cropper.umd.js

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions next/lib/exif-js-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Exif.getData = (img) => new Promise((reslove, reject) => {
let obj = {};
getImageData(img).then(data => {
obj.arrayBuffer = data;
obj.orientation = getOrientation(data);
try {
obj.orientation = getOrientation(data);
} catch {
obj.orientation = -1;
}
reslove(obj)
}).catch(error => {
reject(error)
Expand Down Expand Up @@ -65,17 +69,19 @@ function objectURLToBlob(url, callback) {



function base64ToArrayBuffer(base64) {
function base64ToArrayBuffer(base64, contentType) {
contentType = contentType || base64.match(/^data\:([^\;]+)\;base64,/mi)[1] || ''; // e.g. 'data:image/jpeg;base64,...' => 'image/jpeg'
base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
var binary = atob(base64);
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
var view = new Uint16Array(buffer);
for (var i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i);
view[i] = binary.charCodeAt(i);
}
return buffer;
}

// 步骤二,Unicode码转字符串
// ArrayBuffer对象 Unicode码转字符串
function getStringFromCharCode(dataView, start, length) {
Expand Down
2 changes: 1 addition & 1 deletion next/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const install = function(app: App) {
}

export const globalCropper: vueCropperGlobal = {
version: '1.0.9',
version: '1.1.0',
install,
VueCropper,
}
Expand Down
8 changes: 6 additions & 2 deletions next/lib/vue-cropper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ export default defineComponent({
let img = new Image();
img.onload = () => {
if (this.img === "") {
this.$emit("img-load", "error");
this.$emit("img-load", new Error('图片不能为空'));
return false;
}
Expand All @@ -575,11 +575,15 @@ export default defineComponent({
height = max;
}
this.checkOrientationImage(img, this.orientation, width, height);
}).catch(error => {
this.$emit("img-load", "error");
this.$emit("img-load-error", error);
});
};
img.onerror = () => {
img.onerror = (error) => {
this.$emit("img-load", "error");
this.$emit("img-load-error", error);
};
// 判断如果不是base64图片 再添加crossOrigin属性,否则会导致iOS低版本(10.2)无法显示图片
Expand Down
2 changes: 1 addition & 1 deletion next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-cropper",
"version": "1.0.9",
"version": "1.1.0",
"description": "A simple Vue picture clipping plugin",
"keywords": [
"vue",
Expand Down
15 changes: 5 additions & 10 deletions next/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
v-bind="option"
@realTime="realTime"
@imgLoad="imgLoad"
@imgLoadError="imgLoad"
@cropMoving="cropMoving"
></vueCropper>
</div>
Expand Down Expand Up @@ -236,23 +237,17 @@ export default {
img: "https://avatars2.githubusercontent.com/u/15681693?s=460&v=4"
},
{
img: "http://cdn.xyxiao.cn/Landscape_1.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_2f07496a52314c3e024eaafaba73dd35.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_2.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/mosaic-legacy_2e7480001384708367aa1.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_3.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-i-0813_80f34c63344d44c292dacf4608c7b258.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Landscape_4.jpg"
img: "https://p3-pc.douyinpic.com/aweme/1080x1080/aweme-avatar/tos-cn-avt-0015_48b61ee1b6b34fe945246cd1ccc4243d.jpeg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_1.jpg"
},
{
img: "http://cdn.xyxiao.cn/Portrait_2.jpg"
}
],
option: {
img: "",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-cropper",
"version": "0.6.2",
"version": "0.6.3",
"description": "A simple Vue picture clipping plugin",
"keywords": [
"vue",
Expand Down Expand Up @@ -31,8 +31,8 @@
"babel-plugin-transform-runtime": "^6.23.0",
"babel-polyfill": "^6.26.0",
"babel-runtime": "^6.26.0",
"css-loader": "^1.0.0",
"style-loader": "^0.23.1",
"css-loader": "^6.8.1",
"style-loader": "^3.3.3",
"vue": "^2.5.17",
"vue-loader": "^15.4.2",
"vue-template-compiler": "^2.5.17",
Expand Down
14 changes: 10 additions & 4 deletions src/exif-js-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Exif.getData = (img) => new Promise((reslove, reject) => {
let obj = {};
getImageData(img).then(data => {
obj.arrayBuffer = data;
obj.orientation = getOrientation(data);
try {
obj.orientation = getOrientation(data);
} catch {
obj.orientation = -1;
}
reslove(obj)
}).catch(error => {
reject(error)
Expand Down Expand Up @@ -65,17 +69,19 @@ function objectURLToBlob(url, callback) {



function base64ToArrayBuffer(base64) {
function base64ToArrayBuffer(base64, contentType) {
contentType = contentType || base64.match(/^data\:([^\;]+)\;base64,/mi)[1] || ''; // e.g. 'data:image/jpeg;base64,...' => 'image/jpeg'
base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
var binary = atob(base64);
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
var view = new Uint16Array(buffer);
for (var i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i);
view[i] = binary.charCodeAt(i);
}
return buffer;
}

// 步骤二,Unicode码转字符串
// ArrayBuffer对象 Unicode码转字符串
function getStringFromCharCode(dataView, start, length) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if (typeof window !== 'undefined' && window.Vue) {
export { VueCropper }

export default {
version: '0.6.1',
version: '0.6.3',
install,
VueCropper,
vueCropper: VueCropper
Expand Down
5 changes: 5 additions & 0 deletions src/vue-cropper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ export default {
if (this.img === "") {
this.$emit("imgLoad", "error");
this.$emit("img-load", "error");
this.$emit("img-load", new Error('图片不能为空'));
return false;
}
Expand All @@ -576,12 +577,16 @@ export default {
height = max;
}
this.checkOrientationImage(img, this.orientation, width, height);
}).catch(error => {
this.$emit("img-load", "error");
this.$emit("img-load-error", error);
});
};
img.onerror = () => {
this.$emit("imgLoad", "error");
this.$emit("img-load", "error");
this.$emit("img-load-error", error);
};
// 判断如果不是base64图片 再添加crossOrigin属性,否则会导致iOS低版本(10.2)无法显示图片
Expand Down

1 comment on commit b3067ba

@vercel
Copy link

@vercel vercel bot commented on b3067ba Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

vue-cropper – ./

vue-cropper-git-main-463618622.vercel.app
vue-cropper-463618622.vercel.app

Please sign in to comment.