﻿
var resize = function (imageToScale, maxh, maxw) {
    var ratio = maxh / maxw;
    if (imageToScale.height / imageToScale.width > ratio) {
        // height is the problem
        if (imageToScale.height > maxh) {
            imageToScale.width = Math.round(imageToScale.width * (maxh / imageToScale.height));
            imageToScale.height = maxh;
        }
    } else {
        // width is the problem
        if (imageToScale.width > maxh) {
            imageToScale.height = Math.round(imageToScale.height * (maxw / imageToScale.width));
            imageToScale.width = maxw;
        }
    }
};
