title: Getting orientation of an image JS
body: <p>I actually try to get orientation of images in JS to add a class to it. It seems to work fine on Firefox, but I have issues on other browsers. It works better with very small images, so I guess it's not working if images are not completely loaded... but I can't find a solution to make it works correctly !
  Thanks !</p>
  
  <p>My code :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(document).ready(function() {
   $('.gallery a').find('img').each(function() {
    var imgClass = (this.width / this.height &gt; 1) ? 'landscape' : 'portrait';
    $(this).addClass(imgClass);
   })
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.gallery {
   display: flex;
   flex-wrap: wrap;
   width: 450px;
  }
  .gallery a {
   width: 200px;
   height: 200px;
   display: flex;
   justify-content: center;
   overflow: hidden;
  }
  .gallery a img.landscape {
   align-self: center;
   height: 100%;
   filter: sepia(100%);
  }
  .gallery a img.portrait {
   align-self: center;
   width: 100%;
   filter: grayscale(100%);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="gallery"&gt;
   &lt;a href="http://lorempixel.com/output/city-q-c-1500-1000-3.jpg"&gt;
    &lt;img src="http://lorempixel.com/output/city-q-c-1500-1000-3.jpg"&gt;
   &lt;/a&gt;
   &lt;a href="http://lorempixel.com/output/city-h-c-1000-1500-4.jpg"&gt;
    &lt;img src="http://lorempixel.com/output/city-h-c-1000-1500-4.jpg"&gt;
   &lt;/a&gt;
   &lt;a href="http://lorempixel.com/output/city-q-c-1500-1000-3.jpg"&gt;
    &lt;img src="http://lorempixel.com/output/city-q-c-1500-1000-3.jpg"&gt;
   &lt;/a&gt;
   &lt;a href="http://lorempixel.com/output/city-h-c-1000-1500-4.jpg"&gt;
    &lt;img src="http://lorempixel.com/output/city-h-c-1000-1500-4.jpg"&gt;
   &lt;/a&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>