强制图像方向angularjs [英] Force image orientation angularjs
本文介绍了强制图像方向angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我上传图片时,我有这种奇怪的行为,如果此图片尺寸的高度高于我将图片旋转 90 度时的高度.
I have this odd behavior when I upload an image and if this image size has more height than with I get the image rotated 90 degrees.
检查使用 fiddle>ngImgCrop,这是我上传的图片
check this fiddle that's using ngImgCrop and this is the image that I'm uploading
ngDmgCrop 的代码非常标准:
the code of the ngDmgCrop it's pretty standard:
angular.module('app', ['ngImgCrop'])
.controller('Ctrl', function($scope) {
$scope.myImage='';
$scope.myCroppedImage='';
var handleFileSelect=function(evt) {
var file=evt.currentTarget.files[0];
var reader = new FileReader();
reader.onload = function (evt) {
$scope.$apply(function($scope){
$scope.myImage=evt.target.result;
});
};
reader.readAsDataURL(file);
};
angular.element(document.querySelector('#fileInput')).on('change',handleFileSelect);
});
我该如何解决这个问题?
how can I fix this behavior?
推荐答案
您必须解析图像标题中的 exif 数据,检查 Orientation 标签,并相应地旋转.
You'll have to parse the exif data in the image header, examine the Orientation tag, and rotate accordingly.
我刚刚用这个库解决了同样的问题:Javascript 加载图片
I just solved the same problem with this library: Javascript Load Image
在您的 app.js
var handleFileSelect = function(evt) {
var target = evt.dataTransfer || evt.target;
var file = target && target.files && target.files[0];
var options = {canvas:true};
var displayImg = function(img) {
$scope.$apply(function($scope){
$scope.myImage=img.toDataURL();
});
}
loadImage.parseMetaData(file, function (data) {
if (data.exif) {
options.orientation = data.exif.get('Orientation');
}
loadImage(file, displayImg, options );
});
};
演示:Plunker
干杯.
这篇关于强制图像方向angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文