﻿

// Image Formatting
//  parameters:
//      el - source image
//      w - desired width
//      h - desired height

function formatImage(el, w, h){
    var img = new Image();
    img.src = el.src;

    var x = img.width;
    var y = img.height;

    if (arguments.length < 3 || h == 0 || x == 0 || y == 0)
        return;
    
    var desiredRatio = w / h;
    var originalRatio = x / y;
    
    if (desiredRatio > originalRatio){
        el.height = h;
        el.width = h * originalRatio;
    }
    else{
        el.width = w;
        el.height = w / originalRatio;
    }
}

