javascript - LocalResizeIMG.js在iphone下上传图片旋转了90度,如何解决
程序员文章站
2022-05-14 23:41:40
...
LocalResizeIMG.js在iphone下上传图片旋转了90度,如何解决
回复内容:
LocalResizeIMG.js在iphone下上传图片旋转了90度,如何解决
这个要在这个js
源码里去做图片旋转处理
var angle = '';
this.on('change', function () {
var file = this.files[0];
var URL = window.URL || webkitURL;
var blob = URL.createObjectURL(file);
var BinaryAjax = window.BinaryAjax || '',
EXIF = window.EXIF || '';
if (BinaryAjax && EXIF) {
// get photo orientation and set angle
BinaryAjax(blob, function(o) {
var oExif = EXIF.readFromBinaryFile(o.binaryResponse),
orientation = oExif.Orientation;
switch(orientation) {
case 6:
angle = radians('90deg');
break;
case 3:
angle = radians('180deg');
break;
case 8:
angle = radians('270deg');
break;
}
});
}
// 执行前函数
if($.isFunction(obj.before)) { obj.before(this, blob, file) };
_create(blob, file);
this.value = ''; // 清空临时数据
});
function radians(angle) {
if (typeof angle == 'number') return angle;
return {
rad: function(z) {
return z;
},
deg: function(z) {
return Math.PI / 180 * z;
}
}[String(angle).match(/[a-z]+$/)[0] || 'rad'](parseFloat(angle));
}