본문 바로가기
JAVASCRIPT/이미지객체로 사이즈 구하기

자바스크립트 이미지 객체로 size 구하기

by 정윤재 2008. 10. 20.

function onLoad(){

 //페이지가 시작할 때 이미지 사이즈에 맞춰서 테이블 바꿔주기
 //배경 그림이 크기가 제각각이어서 동적으로 외각 틀의 사이즈를 변경 시켜주어야함
  var imgObj       =   new Image();
//요게 이미지 객체 
imgObj.src    =   './result/<%=java.net.URLEncoder.encode(fileName,"UTF-8")%>';
  var width1=imgObj.width;
  var height1=imgObj.height;

  //alert(width1);
  //alert(height1);
  if(width1>850){
   width1=850;
   //880정도 부터 깨지기 때문에 보기 좋은 사이즈인 850으로 max 사이즈 설정
  }else if(width1<100){
   width1=100;
   //50 이하로 갈 경우  외각 틀이 깨지지만 visual상 100이하로 가면 보기 힘들기 때문에 100으로 min 사이즈 설정
  }
  var table1 = document.getElementById("tableChange");
  table1.rows[0].cells[0].innerHTML='<img src="img/view/photo_line1.gif" width="15" height="15" />';
  table1.rows[0].cells[1].innerHTML='&nbsp;';
  table1.rows[0].cells[2].innerHTML='<img src="img/view/photo_line1_2.gif" width="15" height="15" />';
 
  table1.rows[1].cells[0].innerHTML='&nbsp;';
  table1.rows[1].cells[1].innerHTML='<img src="<%=path%>" width="'+width1+'" height="'+height1+'" border="0" />';
  //이미지 크기를 동적으로 원래 크기에 맞게 맞춰 줌
  table1.rows[1].cells[2].innerHTML='&nbsp;';
 
  table1.rows[2].cells[0].innerHTML='<img src="img/view/photo_line3.gif" width="15" height="15" />';
  table1.rows[2].cells[1].innerHTML='&nbsp;';
  table1.rows[2].cells[2].innerHTML='<img src="img/view/photo_line3_2.gif" width="15" height="15" />';
}


댓글