I came across a helpful code snippet on stackoverflow for determining if an image is portrait or landscape oriented, and applying CSS width and height formatting accordingly.
However, after successfully implementing the code (hence all the $LSC references), I noticed that it immediately defaults to the "else" condition and applies the same styling to all images (setting width to auto and height to 100%).
My question is, what adjustments need to be made to the code in order for it to accurately compare the width and height of the images?
var $LSC = jQuery.noConflict();
$LSC(document).ready(function(){
$LSC(".pg-cat-image").each(function(){
var real_width = $LSC(this).width();
var real_height = $LSC(this).height();
var parentwidth = $LSC(this).parent().width();
var parentheight = $LSC(this).parent().height();
var ratioParent = parentwidth / parentheight;
var ratio = real_width / real_height;
if (ratioParent < ratio) {
$LSC(this).css({'width' : '100%', 'height' : 'auto'});
} else {
$LSC(this).css({'width' : 'auto', 'height' : '100%'});
}
});
});