function drawimage(imgd, fitwidth, fitheight) {
var image = new image();
image.src = imgd.src;
if (image.width > 0 && image.height > 0) {
if (image.width / image.height >= fitwidth / fitheight) {
if (image.width > fitwidth) {
imgd.width = fitwidth;
imgd.height = (image.height * fitwidth) / image.width;
} else {
imgd.width = image.width;
imgd.height = image.height;
}
} else {
if (image.height > fitheight) {
imgd.height = fitheight;
imgd.width = (image.width * fitheight) / image.height;
} else {
imgd.width = image.width;
imgd.height = image.height;
}
}
}
}