gd 썸네일 이용시 그림 짜르기.. 정보
그누보드 gd 썸네일 이용시 그림 짜르기..
본문
스킨 하나 제작 하고 있는데 한 부분을 잘 모르겠네요..
별로 사용을 해본 기능이 아니라서 ㅠ.ㅠ
----------------------------
if (preg_match($cfg[image_extension], $dest_file)) // image 파일인지 체크
{
// 업로드시 기존의 업로드된 thumb 파일을 삭제
@unlink("./data/file/$bo_table/" . $wr["wr_file1"].".thumb");
$tsize = @GetImageSize($dest_file); // $dest_file : bbs/gbupdate에서 upload 된 파일이름
switch($tsize[2]) {
case 1: // GIF image
$oimg = @ImageCreateFromGIF($dest_file); break;
case 2: // JPEG image
$oimg = @ImageCreateFromJPEG($dest_file); break;
case 3: // PNG image
$oimg = @ImageCreateFromPNG($dest_file); break;
}
$trate = $tsize[1] / $tsize[0]; // 이미지 높이 비율
$theight = (int)($twidth * $trate); // 작은이미지의 높이
if (function_exists("imagecreatetruecolor")) {
// This function requires GD 2.0.1 or later.
$timg = @ImageCreateTrueColor($twidth, $theight);
} else {
$timg = @ImageCreate($twidth, $theight);
}
// 1.00.05 GD 버전에 따라
if (function_exists("imagecopyresampled")) {
@ImageCopyReSampled($timg, $oimg, 0, 0, 0, 0, $twidth, $theight, $tsize[0], $tsize[1]);
} else {
// 1.00.02 imagecopyresized -> imagecopyresampled 로 교체
@ImageCopyReSized($timg, $oimg, 0, 0, 0, 0, $twidth, $theight, $tsize[0], $tsize[1]);
}
$thumb_file = $dest_file.".thumb";
@ImageJPEG($timg, $thumb_file, $tquality);
/*
switch($tsize[2]) {
case 1: // GIF image
@ImageGIF($timg, $thumb_file, $tquality); break;
case 2: // JPEG image
@ImageJPEG($timg, $thumb_file, $tquality); break;
case 3: // PNG image
@ImagePNG($timg, $thumb_file, $tquality); break;
}
*/
@chmod($timg,0707);
@ImageDestroy($oimg);
@ImageDestroy($timg);
}
//print_r2($_FILES["wr_file1"]); exit;
//print_r2($_FILES); exit;
?>
----------------------------
위 소스는 gd 를 이용하셔 썸네일 생성 하는 소스 입니다. 어느분 소스 인지는 정확히... 기억이 ^^;;
보통 썸네일은 가로 세로 비율로 생성 되지만. 가로 의 싸이즈와 세로 싸이즈가 고정이고.
그외의 부분은 잘라 버리고자 합니다....
1000 * 500 의 이미지를 가로 기준으로 100으로 했을때 세로는 50 으로 되겠죠..
1000*1000 이미지를 올렸을 경우도 100*100의 비율로 될것입니다..
하지만 어떤이미지를 올려도 100*50 의 썸네일을 생성 하고자합니다. 나머지 부분은 자르고자 합니다.
부탁 드립니다.
별로 사용을 해본 기능이 아니라서 ㅠ.ㅠ
----------------------------
if (preg_match($cfg[image_extension], $dest_file)) // image 파일인지 체크
{
// 업로드시 기존의 업로드된 thumb 파일을 삭제
@unlink("./data/file/$bo_table/" . $wr["wr_file1"].".thumb");
$tsize = @GetImageSize($dest_file); // $dest_file : bbs/gbupdate에서 upload 된 파일이름
switch($tsize[2]) {
case 1: // GIF image
$oimg = @ImageCreateFromGIF($dest_file); break;
case 2: // JPEG image
$oimg = @ImageCreateFromJPEG($dest_file); break;
case 3: // PNG image
$oimg = @ImageCreateFromPNG($dest_file); break;
}
$trate = $tsize[1] / $tsize[0]; // 이미지 높이 비율
$theight = (int)($twidth * $trate); // 작은이미지의 높이
if (function_exists("imagecreatetruecolor")) {
// This function requires GD 2.0.1 or later.
$timg = @ImageCreateTrueColor($twidth, $theight);
} else {
$timg = @ImageCreate($twidth, $theight);
}
// 1.00.05 GD 버전에 따라
if (function_exists("imagecopyresampled")) {
@ImageCopyReSampled($timg, $oimg, 0, 0, 0, 0, $twidth, $theight, $tsize[0], $tsize[1]);
} else {
// 1.00.02 imagecopyresized -> imagecopyresampled 로 교체
@ImageCopyReSized($timg, $oimg, 0, 0, 0, 0, $twidth, $theight, $tsize[0], $tsize[1]);
}
$thumb_file = $dest_file.".thumb";
@ImageJPEG($timg, $thumb_file, $tquality);
/*
switch($tsize[2]) {
case 1: // GIF image
@ImageGIF($timg, $thumb_file, $tquality); break;
case 2: // JPEG image
@ImageJPEG($timg, $thumb_file, $tquality); break;
case 3: // PNG image
@ImagePNG($timg, $thumb_file, $tquality); break;
}
*/
@chmod($timg,0707);
@ImageDestroy($oimg);
@ImageDestroy($timg);
}
//print_r2($_FILES["wr_file1"]); exit;
//print_r2($_FILES); exit;
?>
----------------------------
위 소스는 gd 를 이용하셔 썸네일 생성 하는 소스 입니다. 어느분 소스 인지는 정확히... 기억이 ^^;;
보통 썸네일은 가로 세로 비율로 생성 되지만. 가로 의 싸이즈와 세로 싸이즈가 고정이고.
그외의 부분은 잘라 버리고자 합니다....
1000 * 500 의 이미지를 가로 기준으로 100으로 했을때 세로는 50 으로 되겠죠..
1000*1000 이미지를 올렸을 경우도 100*100의 비율로 될것입니다..
하지만 어떤이미지를 올려도 100*50 의 썸네일을 생성 하고자합니다. 나머지 부분은 자르고자 합니다.
부탁 드립니다.
댓글 전체