[픽콤자작SCRIPT]이미지 사이즈 자동조정 : ImageResizer

/*
 * version : 1
 * var img = new ImageResizer("img", "/img/temp.gif", "viewImg", 200, 200);
 * img.imgChecker();
 *
 * var [인스턴스명] = new StaticMenu("[인스턴스명]", [원본 image Url], [Html Tag로 선언된 보여질 IMG의 ID], [최대 가로길이], [최대 세로길이]);
 *
 * 모든항목 필수
 * instanceName         : 선언된 instance의 이름 : timer 지정시 대상 object 선별에 사용
 * srcUrl    : 원본 image의 URL
 * displySrc   : 보여질 Image Tag의 ID
 * maxWidth    : 제한되어질 최대 가로길이
 * maxHeight   : 제한되어질 최대 세로길이
 *
 *
 * var imgList = new Array();
 * imgList[imgList.length] = new ImageResizer("imgList["+imgList.length+"]", "/img/temp.gif", "viewImg"+imgList.length, 200, 200);
 * imgList[imgList.length-1].imgChecker();
 * imgList[imgList.length] = new ImageResizer("imgList["+imgList.length+"]", "/img/temp.gif", "viewImg"+imgList.length, 200, 200);
 * imgList[imgList.length-1].imgChecker();
 * 위와 같이 배열에 담겨질 경우에 instanceName을 위와 같이 선언한다.
 */
    function ImageResizer(instanceName, srcUrl, displySrc, maxWidth, maxHeight){
        this.thisInstanceName = instanceName;
        this.img = new Image();
        this.img.src = srcUrl;
        this.displySrc = displySrc;
        this.maxWidth = maxWidth;
        this.maxHeight = maxHeight;
       
        this.imgChecker = function (){
            if(this.img!=null && this.img.complete == true && this.displySrc!=null){
                var originalImg = this.img;
                var targetImg = document.getElementById(this.displySrc);
                if(originalImg.width > originalImg.height){
                    if(eval(originalImg.width>this.maxWidth)){
                        originalImg.width = this.maxWidth;
                    }
                    targetImg.width = originalImg.width;
                }else{
                    if(eval(originalImg.height>this.maxHeight)){
                        originalImg.height = this.maxHeight;
                    }
                    targetImg.width = originalImg.width;
                }
                targetImg.src = originalImg.src;
                targetImg.style.cursor = "hand";
                targetImg.onclick = openImageTemplerOriginImg;
            }else{
                this.startSleep();
            }
        }
       
        this.startSleep = function (){
            timer_id = setTimeout(this.thisInstanceName+".imgChecker()", 100);
        }
    }
    function openImageTemplerOriginImg(){
        if(!endsWith(window.event.srcElement.src, 'temp.gif')){
            var imgObj = new Image();
            imgObj.src = window.event.srcElement.src;
            var wopt = "scrollbars=yes,status=no,resizable=yes";
                wopt += ",left=0,top=0";
            if(imgObj.width >= (screen.width-20)){
            }else{
                wopt += ",width=" + (imgObj.width+18);
            }
            if(imgObj.height >= (screen.height - 60)){
            }else{
                wopt += ",height=" + imgObj.height;
            }
            var wbody = "<head><title>▒ 원본그림 보기</title>";
            wbody += "</head>";
            wbody += "<body style='margin:0px;padding:0px;' valign='middle' align='center'>";
            wbody += "<a href='javascript:window.close()'><img src='" + imgObj.src + "' border=0></a>";
            wbody += "</body>";
            winResult = window.open("about:blank","",wopt);
            winResult.document.open("text/html", "replace");
            winResult.document.write(wbody);
            winResult.document.close();
        }
        return;
    }

Press ESC to close