이미지 리사이징..조금수정 > 그누4 팁자료실

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.

이미지 리사이징..조금수정 정보

이미지 리사이징..조금수정

본문

$board[bo_image_width] //------------이부분은 보드관리자 화면에서 결정하구요.
$board[bo_1]//------------------썸네일 이미지 폭
$board[bo_2]//------------------썸네일 이미지 질


write_update.skin.php에 아래와 같이 하니 잘되는군요....

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';

    $sql2=" select * from $g4[board_file_table] where  bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no asc";
    $results2 = sql_query($sql2);
    for ($d=0; $row2=sql_fetch_array($results2); $d++)  { //~~~~~~~~~~~~~~~~~~~~~~~~~~~

if ($_FILES[bf_file][name][$d])
{
$file = $data_path .'/'. $row2[bf_file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file))
{
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
break;

$rate = $board[bo_image_width] / $size[0];
$height = (int)($size[1] * $rate);

@unlink($data_path.'/'.$row2[bf_file]);
$dst = imagecreatetruecolor($board[bo_image_width], $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_image_width], $height, $size[0], $size[1]);
// imagepng($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]);
                                                //이부분이 png 압축방식이어서 이미지 커졌나 봅니다.
                                                //아래처럼 하니 줄어드는 것을 확실히 느껴집니다....^^   
                                                  imagejpeg($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]);
chmod($data_path.'/'.$row2[bf_file], 0606);
//---------->madem님이 알려주신 부분입니다.^^
$bf_size = @filesize(addslashes($file));
$sql = " update $g4[board_file_table]
set bf_filesize = '$bf_size'
where  bo_table = '$bo_table' and wr_id = '$wr_id'  ";
sql_query($sql);
 //---------->madem님이 알려주신 부분입니다.^^

 }
 }
 }
추천
3

댓글 10개

감사 합니다...
지난번 올려 주신 자료 생각만 하다가 이번에 갑자기 큰사진들이
마구 올라와서 마침 다시 고민 중이던 차에 어쩜 이리 딱 맞춰서
올려 주셨는지.....너무 감사 합니다

어찌 보답을 드려 할찌.......^^
잘 되는 데요............ 한가지 단점이 있습니다.
예를 들어 저는 넓이를 1000으로 잡았는데요........
1000이상은 1000으로 잘 되는 반면에.......
1000미만[800px] 을 올려도 1000px로 다시 생성하는 듯 합니다.

정해진 사이즈 미만은 그냥 보여주는 기능은 어려울까요?
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';

    $sql2=" select * from $g4[board_file_table] where  bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no asc";
    $results2 = sql_query($sql2);
    for ($d=0; $row2=sql_fetch_array($results2); $d++)  { //~~~~~~~~~~~~~~~~~~~~~~~~~~~

if ($_FILES[bf_file][name][$d])
{
$file = $data_path .'/'. $row2[bf_file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file))
{
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
break;

$rate = $board[bo_image_width] / $size[0];
$height = (int)($size[1] * $rate);

if ($size[0] > $board[bo_image_width]){

@unlink($data_path.'/'.$row2[bf_file]);
$dst = imagecreatetruecolor($board[bo_image_width], $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $board[bo_image_width], $height, $size[0], $size[1]);
// imagepng($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]);
                                                //이부분이 png 압축방식이어서 이미지 커졌나 봅니다.
                                                //아래처럼 하니 줄어드는 것을 확실히 느껴집니다....^^   
                                                  imagejpeg($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]);
chmod($data_path.'/'.$row2[bf_file], 0606);
//---------->madem님이 알려주신 부분입니다.^^
$bf_size = @filesize(addslashes($file));
$sql = " update $g4[board_file_table]
set bf_filesize = '$bf_size'
where  bo_table = '$bo_table' and wr_id = '$wr_id'  ";
sql_query($sql);
 //---------->madem님이 알려주신 부분입니다.^^
 }
 }
 }
 }

중간에
if ($size[0] > $board[bo_image_width]){
그리고 마지막에
}
이렇게 추가 했습니다...

제 어설픈 이론으로는 게시판 관리자에서 정한 넓이 값보다 이미지 넓이가
크다면 이미지 리사이징을 실행 하고 아님 말고...

이렇게 되는 듯 하는 데요...

일단 저는 현재까지는 이상이 없이 잘 되는 듯 보입니다.
전체 보드에 적용시 아래와 같이 하면 될것 같네요.

// 첨부 이미지 리사이징, 아래 보드는 제외함(원size대로).
if ($bo_table != "aaaa" && $bo_table != "bbbb" ) {
$img_limit_width = 800; // 제한할 이미지 폭
$img_quality = 100; // 이미지 품질
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
    $sql2=" select * from $g4[board_file_table] where  bo_table = '$bo_table' and wr_id = '$wr_id' order by bf_no asc";
    $results2 = sql_query($sql2);
    for ($d=0; $row2=sql_fetch_array($results2); $d++)  { //~~~~~~~~~~~~~~~~~~~~~~~~~~~
if ($_FILES[bf_file][name][$d])
{
$file = $data_path .'/'. $row2[bf_file];
if (preg_match("/\.(jp[e]?g|gif|png)$/i", $file))
{
$size = getimagesize($file);
if ($size[2] == 1)
$src = imagecreatefromgif($file);
else if ($size[2] == 2)
$src = imagecreatefromjpeg($file);
else if ($size[2] == 3)
$src = imagecreatefrompng($file);
else
break;
$rate = $img_limit_width / $size[0];
$height = (int)($size[1] * $rate);
if ($size[0] > $img_limit_width){
@unlink($data_path.'/'.$row2[bf_file]);
$dst = imagecreatetruecolor($img_limit_width, $height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $img_limit_width, $height, $size[0], $size[1]);
// imagepng($dst, $data_path.'/'.$row2[bf_file], $board[bo_2]);
//이부분이 png 압축방식이어서 이미지 커졌나 봅니다.
//아래처럼 하니 줄어드는 것을 확실히 느껴집니다....^^   
imagejpeg($dst, $data_path.'/'.$row2[bf_file], $img_quality);
chmod($data_path.'/'.$row2[bf_file], 0606);
//---------->madem님이 알려주신 부분입니다.^^
$bf_size = @filesize(addslashes($file));
$sql = " update $g4[board_file_table]
set bf_filesize = '$bf_size'
where  bo_table = '$bo_table' and wr_id = '$wr_id'  ";
sql_query($sql);
 //---------->madem님이 알려주신 부분입니다.^^
 }
 }
 }
 }
}
전체 1 |RSS
그누4 팁자료실 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT