I have a JS function called isPortrait, to determine the orientation of a given photo. The problem is, when I call it, it always returns false. However, the alert() is works perfectly, and returns the resolution of the photo. How can I fix it?
function isPortrait(src) {
var is = false;
var img = new Image();
img.src = src;
img.onload = function() {
alert(img.width+"x"+img.height);
if(img.height>img.width)
{
is = true;
}
}
return is;
}
My solution (using a global variable):
window.isportrait = false;
function isPortrait(src) {
var img = new Image();
img.src = src;
img.onload = function() {
if(img.height>img.width)
{
window.isportrait = true;
}
else
{
window.isportrait = false;
}
}
}