Answer the question
In order to leave comments, you need to log in
Rotate photo in iOs Safari on Canvas?
Hello, tell me please. On iOS, Safari rotates a photo 90 degrees when I load it into Canvas. I googled that this is a problem in the photo metadata. Can you suggest a solution? Thank you.
Answer the question
In order to leave comments, you need to log in
If you don’t want to pull libs, then there is such a piece. True, this was written a long time ago, how it works now - I don’t know
// ...
getOrientation(file, function(orientation) {
if (orientation == 8) { // -90deg
$modal.trigger('image-action', );
}
else if (orientation == 6) { // 90deg
$modal.trigger('image-action', );
}
else if (orientation == 3) { // -180deg
$modal.trigger('image-action', );
$modal.trigger('image-action', );
}
});
// ...
function getOrientation(file, callback) {
var reader = new FileReader();
reader.onload = function(e) {
var view = new DataView(e.target.result);
if (view.getUint16(0, false) != 0xFFD8) return callback(-2);
var length = view.byteLength/2, offset = 2;
while (offset < length) {
var marker = view.getUint16(offset, false);
offset += 2;
if (marker == 0xFFE1) {
if (view.getUint32(offset += 2, false) != 0x45786966) return callback(-1);
var little = view.getUint16(offset += 6, false) == 0x4949;
offset += view.getUint32(offset + 4, little);
var tags = view.getUint16(offset, little);
offset += 2;
for (var i = 0; i < tags; i++)
if (view.getUint16(offset + (i * 12), little) == 0x0112)
return callback(view.getUint16(offset + (i * 12) + 8, little));
}
else if ((marker & 0xFF00) != 0xFF00) break;
else offset += view.getUint16(offset, false);
}
return callback(-1);
};
reader.readAsArrayBuffer(file);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question