I'm working on a solution to fix an issue in which images made from certain phones appear either sideways or upside down due to them having orientation in the exif data. So far I have that I get orientation, but this variable in not passed back in time for the next rotation steps.
function getOrientation(image){
let ort = 1;
EXIF.getData(image, function () {
ort = EXIF.getTag(this, 'Orientation');
});
return ort;
}
The value from ort is later used in combination with a canvas to rotate the uploaded image. As shown below, but each change makes the value become 1 or undefined.
let orientation = getOrientation(files);
let data = rotateImage(files, orientation);
What is the best way to pass the variable called ort back to the function that made a call to getOrientation()?
After trying multiple things I was able to fix it by making orietation a global variable and let the rotateImage have a delayed execution with setTimeout. By doing this getOrientation can finish and rotateImage can use the let orientation after the timeout is over.