이곳은 ZEROBOARD 4버전 관련 질문/답변 게시판입니다.
<?php
$upload_image1=$upload_image2="";
$maxWidth = 260; //이미지 최대넓이
$maxHeight = 260; //이미지 최대높이
if(eregi("\.jpg",$file_name1)||eregi("\.gif",$file_name1)||eregi("\.png",$file_name1)){
$imgInfo = getimagesize("../$data[file_name1]");
$width = $imgInfo[0];
$height = $imgInfo[1];
//이미지 사이즈 비율조절 시작.
if($imgInfo[0]>$imgInfo[1])
{ $percentage=$imgInfo[0]/$maxWidth; }
elseif($size[1]>$imgInfo[0])
{ $percentage=$imgInfo[1]/$maxHeight; }
else
{ $percentage=$imgInfo[0]/$maxWidth; }
//크기에서 긴쪽을 나누어서 비율을 정한다.
$y_size=$imgInfo[1]/$percentage;
$x_size=$imgInfo[0]/$percentage;
//이미지 사이즈 비율조절 끝.
$y_size = ceil(($maxWidth / $width) * $height); //비율조절
$upload_image1="<img src=../$data[file_name1] border=0 name=zb_target_resize style=\"cursor:hand\" width=".$x_size."px height=".$y_size."px><br>";
}
if(eregi("\.jpg",$file_name2)||eregi("\.gif",$file_name2)||eregi("\.png",$file_name2)){
$imgInfo = getimagesize("../$data[file_name2]");
$width = $imgInfo[0];
$height = $imgInfo[1];
$x_size = ($width > $maxWidth) ? $maxWidth : $width; //width값 지정
$y_size = ceil(($maxWidth / $width) * $height); //비율조절
$upload_image2="<img src=../$data[file_name2] border=0 name=zb_target_resize style=\"cursor:hand\" width=".$x_size."px height=".$y_size."px><br>";
}
?>
<?=$hide_download1_start?><?=$upload_image1?><?=$hide_download1_end?>
<?=$hide_download2_start?><?=$upload_image2?><?=$hide_download2_end?>
<?
//이미지 리사이징
$m = preg_match_all("/<img[^>]*src=[\"']?([^>\"']+)[\"']?[^>]*>/i",$data[memo], $output);
if ($m) {
for ($j=0;$j<$m;$j++) {
if(@getimagesize($output[1][$j])){
$imgInfo = getimagesize($output[1][$j]);
$width = $imgInfo[0];
$height = $imgInfo[1];
}else{
$width = $maxWidth;
$height = ceil($width);
}
$x_size = ($width > $maxWidth) ? $maxWidth : $width; //width값 지정
$y_size = ceil(($maxWidth / $width) * $height); //비율조절
$data[memo] = str_replace($output[0][$j],'<img src="'.$output[1][$j].'" width='.$width.'px height='.$y_size.'px>',$data[memo]);
}
}
?>
빨간색 부분때문에 리사이즈가 가로 길이로 되는 거 같은데요. 이미지 비율에 맞게 리사이즈 하려면 어떻게 고쳐야할지요...
아무리 고민하고 고쳐봐도 되질 않아 문의드립니다.
