javascript - Exif 返回值为 -6
问题描述
我有以下 javascript,我试图用它来检查我的图像在预览时的旋转。我的一些图像在预览时被旋转,所以我试图使用 exif 库来处理旋转。
在下面的代码中,我得到 -6 的 console.log('Exif=', EXIF.getTag(this, "Orientation")); 然后我的其他 console.logs 都没有转储。我的控制台中没有任何错误,但看起来该功能刚刚退出。有人可以帮忙吗。即使我将其中一个 case 语句更改为 -6,该 case 语句仍然不会被调用。有任何想法吗?
// UPLOAD IMAGE PREVIEW
function readURL(input) {
console.log("aaaa");
if (input.files && input.files[0]) {
var reader = new FileReader();
console.log("here544");
reader.onload = function (e) {
var img = $('#_nc_image_default')
fixExifOrientation(img)
console.log("here5");
img.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
function fixExifOrientation($img) {
$img.on('load', function() {
EXIF.getData($img[0], function() {
console.log('Exif=', EXIF.getTag(this, "Orientation"));
switch(parseInt(EXIF.getTag(this, "Orientation"))) {
case 2:
$img.addClass('flip');
break;
case 3:
$img.addClass('rotate-180');
break;
case 4:
$img.addClass('flip-and-rotate-180');
break;
case 5:
$img.addClass('flip-and-rotate-270');
break;
case 6:
$img.addClass('rotate-90');
break;
case 7:
$img.addClass('flip-and-rotate-90');
break;
case 8:
$img.addClass('rotate-270');
break;
default:
console.log("here");
break;
}
console.log("here2");
$img.addClass('flip-and-rotate-180');
});
console.log("here3");
});
console.log("here4");
}
解决方案
推荐阅读
- python - Groupby相当于多个列和多个聚合在pivot中
- express - 注销用户的问题。使用 JWT 身份验证的 Express 服务器 API
- jquery - 使用 jQuery 的 div 下拉菜单
- virtual-machine - 机器可以在没有使用 Powershell 安装 VMware Tools 的情况下“关闭来宾操作系统”吗?
- php - 如何在保存到数据库之前从 $_POST 计算 (+) 值
- c - 我对 fgets() 和 strtok() 的使用对于解析多行输入是否不正确?
- cucumber - 黄瓜钩子场景。嵌入总是在项目根目录创建屏幕截图
- c# - 我想在关闭我的 UWP 应用程序之前存储一个 int 值
- php - 如何从查询中排除特定选择
- ios - 如何在 Laravel 中验证 HTTP 请求