title: Adding CSS Class According to Image Ratio
body: <p>I'm creating an image gallery with dozens of landscape and portrait images on a single page. I want to style each image with a dynamically added CSS class (i.e. ".landscape" for landscape images) according to its orientation.</p>
  
  <p>I came across the code below (from 2003!) For determining the ratio and adding a class for a single image, but I need the classes to be added automatically for all images within a certain div id. Honestly, I just don't know enough about JavaScript or jQuery to solve this on my own.</p>
  
  <pre><code>&lt;script language="JavaScript" type="text/javascript"&gt;
  &lt;!--
  function getDim() {
  myImage = new Image;
  myImage.src="myimage.gif";//path to image
  document.divImage.src=myImage.src;
  var imgProp;
  var width = myImage.width;
  var height = myImage.height;
  var ratio = width/height;
  if ( ratio &gt; 1 ) {
  document.getElementById('image').className="portrait";
  }
  else {
  document.getElementById('image').className="landscape";
  }
  }
  //--&gt;
  &lt;/script&gt; 
  </code></pre>