我正在使用JavaScript LoadImage.parseMetaData(https://github.com/blueimp/JavaScript-Load-Image)尝试获取Web上图像的方向,以便旋转它。
如果我硬编码方向(请参见第二个loadImage调用中的“orientation:3”),我可以旋转它...但我正在尝试使用loadImage.parseMetaData获取方向信息。
我已经使用基于Web的EXIF解析器,并且图像中有方向信息。
当我调用loadImage.parseMetaData时,“data.exif”似乎为空。 请参见此fiddle: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();
任何正确定向图像的想法或替代方法都受到欢迎。