我正在使用 JavaScript LoadImage.parseMetaData ( https://github.com/blueimp/JavaScript-Load-Image ) 来尝试获取网络上图像的方向,因此我可以旋转它。
如果我对方向进行硬编码(请参阅第二个 loadImage 调用中的“orientation: 3”),我可以旋转它……但我正在尝试使用 loadImage.parseMetaData 来获取方向。
我使用了基于 Web 的 EXIF 解析器,并且图像中存在方向信息。
当我调用 loadImage.parseMetaData 时,“data.exif”似乎为空。看到这个小提琴:http: //jsfiddle.net/aginsburg/GgrTM/13/
var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://www.filepicker.io/api/file/U0D9Nb9gThy0fFbkrLJP', true);
xhr.responseType = 'blob';
xhr.onload = function(e) {
if (this.status == 200) {
// Note: .response instead of .responseText
console.log ("got image");
var blob = new Blob([this.response], {type: 'image/png'});
console.log("about to parse blob:" + _.pairs(this.response));
loadImage.parseMetaData(blob, function (data) {
console.log("EXIF:" + _.pairs(data))
var ori ="initial";
if (data.exif) {
ori = data.exif.get('Orientation');
}
console.log("ori is:" + ori);
});
var loadingImage = loadImage(
blob,
function (img) {
console.log("in loadingImage");
document.body.appendChild(img);
},
{maxWidth: 600,
orientation: 3,
canvas: true,
crossOrigin:'anonymous'
}
);
if (!loadingImage) {
// Alternative code ...
}
}
};
xhr.send();
欢迎任何正确定位图像的想法或替代方法。