function resize(image, re_width, re_height) {
    var org = getImageSize(image);
    var fix = {width: org.width, height: org.height};
/*
    if (org.width > re_width || org.height > re_height) {
        if (org.width >= org.height) {
            fix.width = re_width;
            fix.height = Math.floor(org.height / org.width * re_height);
        } else {
            fix.width = Math.floor(org.width / org.height * re_width);
            fix.height = re_height;
        }
    } else {
        fix.width = re_width;
        fix.height = re_height;
    }
*/

    if (fix.width > re_width) {
        var per = re_width / fix.width;
        fix.width = parseInt(fix.width * per);
        fix.height = parseInt(fix.height * per);
    }

    if (fix.height > re_height) {
        var per = re_height / fix.height;
        fix.width = parseInt(fix.width * per);
        fix.height = parseInt(fix.height * per);
    }

    if (fix.width < re_width / 2) {
        fix.width = fix.width * 2;
    }

    if (fix.height < re_height / 2) {
        fix.height = fix.height * 2;
    }

    image.width = fix.width;
    image.height = fix.height;
    image.style.width = fix.width;
    image.style.height = fix.height;

    if (fix.width != re_width) {
        image.style.position = 'relative';
        image.style.left = parseInt((re_width - fix.width) / 2);
    }

    if (fix.height != re_height) {
        image.style.position = 'relative';
        image.style.top = parseInt((re_height - fix.height) / 2);
    }
}

function getImageSize(image) {
    var w = image.width;
    var h = image.height;

    if (typeof image.naturalWidth !== "undefined") {
        w = image.naturalWidth;
        h = image.naturalHeight;
    } else if (typeof image.runtimeStyle !== "undefined") {
        var run = image.runtimeStyle;
        var org = {width: run.width, height: run.height};

        run.width = "auto";
        run.height = "auto";

        w = image.width;
        h = image.height;

        run.width = org.width;
        run.height = org.height;

    } else if (typeof image.removeAttribute !== "undefined") {
        var org = {width: image.width, height: image.height};

        image.style.width = 'auto';
        image.style.height = 'auto';

        image.removeAttribute("width");
        image.removeAttribute("height");

        w = image.width;
        h = image.height;

        image.width = org.width;
        image.height = org.height;
    }

    return {width: w, height: h};
}
