[javascript] 이미지 리사이징

< script>
function imgRsize(img, rW, rH){
var iW = img.width;
var iH = img.height;
var g = new Array;
if(iW < rW && iH < rH) { // 가로세로가 축소할 값보다 작을 경우
g[0] = iW;
g[1] = iH;
} else {
if(img.width > img.height) { // 원크기 가로가 세로보다 크면
g[0] = rW;
g[1] = Math.ceil(img.height * rW / img.width);
} else if(img.width < img.height) { //원크기의 세로가 가로보다 크면
g[0] = Math.ceil(img.width * rH / img.height);
g[1] = rH;
} else {
g[0] = rW;
g[1] = rH;
}
if(g[0] > rW) { // 구해진 가로값이 축소 가로보다 크면
g[0] = rW;
g[1] = Math.ceil(img.height * rW / img.width);
}
if(g[1] > rH) { // 구해진 세로값이 축소 세로값가로보다 크면
g[0] = Math.ceil(img.width * rH / img.height);
g[1] = rH;
}
}
g[2] = img.width; // 원사이즈 가로
g[3] = img.height; // 원사이즈 세로
return g;
}

function gg(img, ww, hh, aL){
var tt = imgRsize(img, 400, 400);
img.width = tt[0];
img.height = tt[1];
if(aL){
img.onclick = function(){
wT = Math.ceil((screen.width - tt[2])/2.6); // 클라이언트 중앙에 이미지위치.
wL = Math.ceil((screen.height - tt[3])/2.6);
mm = window.open(img.src, 'viewOrig', 'width='+tt[2]+',height='+tt[3]+',top='+wT+',left='+wL);
mm.document.body.style.margin = 0; // 마진제거
mm.document.body.style.cursor = "hand";
mm.focus();
if(mm.document.body.onclick) mm.close(); //미해결부분
}
img.style.cursor = "hand";
}
}
// 사용법 gg(this, 400, 400, 1);
// 이미지경로, 가로크기제한, 세로크기제한, 원본새창링크


< img src='/tc/attach/image/465544.jpg' onload='gg(this, 400, 400, 1)'>

크리에이티브 커먼즈 라이센스
Creative Commons License
이올린에 북마크하기

Posted by 홍반장

2007/03/16 11:46 2007/03/16 11:46
Response
No Trackback , No Comment
RSS :
http://tcbs17.cafe24.com/tc/rss/response/2325

Trackback URL : http://tcbs17.cafe24.com/tc/trackback/2325

« Previous : 1 : ... 4087 : 4088 : 4089 : 4090 : 4091 : 4092 : 4093 : 4094 : 4095 : ... 6391 : Next »

블로그 이미지

- 홍반장

Archives

Recent Trackbacks

Calendar

«   2024/04   »
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        
Statistics Graph

Site Stats

Total hits:
183996
Today:
424
Yesterday:
394