﻿var flag = false;

function DrawImage(ImgD, w,h)
{
    var maxW = 100, maxH = 80;
    if (w != null && h != null)
        maxW = w, maxH = h;

    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0)
    {
        flag = true;
        if (image.width / image.height >= maxW / maxH)
        {
            if (image.width > maxW)
                ImgD.width = maxW,ImgD.height = (image.height * maxW) / image.width;
            else
                ImgD.width = image.width,ImgD.height = image.height;
        }
        else
        {
            if (image.height > maxH)
                ImgD.height = maxH,ImgD.width = (image.width * maxH) / image.height;
            else
                ImgD.width = image.width, ImgD.height = image.height;
        }
    }
}
