CallWall / CallWall.Web

Web host for the CallWall product. Hosts the Cloud client and any downloads
0 stars 1 forks source link

Image scaling alg #119

Open LeeCampbell opened 8 years ago

LeeCampbell commented 8 years ago

Currently the image scaling alg is broken I think. I believe that it assumes at most one dimension is too large.

This alg seems much more simple. Can we validate with a good set of tests.

function ScaleImage(srcWidth, srcHeight, targetWidth, targetHeight) {
    var result = { width: 0, height: 0 };

    if ((srcWidth <= 0) || (srcHeight <= 0) || (targetWidth <= 0) || (targetHeight <= 0)) {
        return result;
    }

    var xScaling = targetWidth / srcWidth;
    var yScaling = targetHeight / srcHeight;
    if (xScaling < yScaling){
        return { width: targetWidth, height: srcHeight * xScaling };
    }
    else
    {
        return { width: srcWidth * yScaling, height: targetHeight };
    }
}