Javascript 如何使用Exif在预览时固定图像旋转
我的一些图像在预览时旋转(在用户选择它们之后)。我试图添加一个Exif函数,但它仍然在旋转图片。我相信我错过了一些小东西。我的代码中是否缺少一些东西,或者是否需要添加一个库Javascript 如何使用Exif在预览时固定图像旋转,javascript,exif,image-rotation,exif-js,Javascript,Exif,Image Rotation,Exif Js,我的一些图像在预览时旋转(在用户选择它们之后)。我试图添加一个Exif函数,但它仍然在旋转图片。我相信我错过了一些小东西。我的代码中是否缺少一些东西,或者是否需要添加一个库 // UPLOAD IMAGE PREVIEW function readURL(input) { if (input.files && input.files[0]) { var reader = new FileReader(); reader.onload = function(e
// UPLOAD IMAGE PREVIEW
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
var img = $('#_nc_image_default')
img.attr('src', e.target.result);
fixExifOrientation(img)
};
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;
}
});
});
}
似乎在调用exif之前图像就已经加载了。虽然我尝试过移动exif函数,但它仍然无法修复旋转。似乎在调用exif之前图像就已经加载了。虽然我尝试过移动exif函数,但它仍然无法修复旋转。