how to Calculate whether an image is landscape or portrait

geovani075 picture geovani075 · Jun 3, 2013 · Viewed 22.7k times · Source

I am creating an image gallery with jquery. Is there any possibilities to Calculate whether an image is landscape or portrait using jquery?

Thanks for your support.

Answer

Martyn picture Martyn · Jun 3, 2013

You can simply compare width and height of the image.

var someImg = $("#someId");
if (someImg.width() > someImg.height()){
    //it's a landscape
} else if (someImg.width() < someImg.height()){
    //it's a portrait
} else {
    //image width and height are equal, therefore it is square.
}