﻿

function changeImg(obj, width, height) {
    var scale, comp, w = obj.width, h = obj.height;
    if (w > width || h > height) {
        var scale1 = w / width;
        var scale2 = h / height;
        if (scale1 > scale2) { scale = scale1; comp = obj.wi } else { scale = scale2; }
        w = Math.round(w / scale); h = Math.round(h / scale);
        obj.width = w; obj.height = h;
    }
    obj.style.padding = (height - h) / 2 + "px " + (width - w) / 2 + "px";
}
