테스트 사이트 - 개발 중인 베타 버전입니다

간절.. 썸네일 원본비율 출력 질문입니다!

· 11년 전 · 2399 · 1
http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=139676&sfl=mb_id%2C1&stx=dodo

요 게시판을 사용중인데요.

썸네일이 원본 비율 유지하면서 출력되는 방법을 모르겠습니다.
저도 노력한다고 했는데 몇 시간째 연구해도 해결이 되지 않습니다.


아마도 요 파일에 정답이 있을것 같은데요 skin.lib.php

부디 도와주시면 감사하겠습니다


---------------

<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

if (!function_exists("makeThumbs")) {

function makeThumbs($oriPath, $oriFileName, $thmWidth="", $thmHeight="", $thmAlt="") {
global $g4, $board_skin_path;

$errorFilePrt = "<img src=\"".$board_skin_path."/img/noimage.gif\" border=\"0\" alt=\"이미지 없음\" />";

$oriFile = $oriPath . "/" . $oriFileName;
if (is_file($oriFile) == false) return $errorFilePrt; // 원본 부재

$thmPath = $oriPath . "/thumbs";
$thmFile = $thmPath . "/" . $oriFileName;

$oriSize = getimagesize($oriFile);
$oriWidth = $oriSize[0];
$oriHeight = $oriSize[1];
$oriType = $oriSize[2];

if ($oriType > 3) return $errorFilePrt; // 원본 이미지 타입 오류

$oriRate = $oriWidth / $oriHeight;

if ($thmWidth == "" && $thmHeight == "") return $errorFilePrt; // 썸네일 사이즈 미지정

if ($thmWidth == "") $thmWidth = $thmHeight * $oriRate;
if ($thmHeight == "") $thmHeight = $thmWidth / $oriRate;

$widthRate = $thmWidth / $oriWidth;
$heightRate = $thmHeight / $oriHeight;

$oriFilePrt = "<img src=\"".$oriFile."\" width=\"".$oriWidth."\" height=\"".$oriHeight."\" border=\"0\" alt=\"".$thmAlt."\" />";

if ($widthRate >= 1 && $heightRate >= 1) return $oriFilePrt; // 리사이징 불필요

if (file_exists($thmFile)) { // 썸네일 유무

$fp = fopen($thmFile, "r");
$fstat = fstat($fp);
$thmFileTime = $fstat['ctime'];
fclose($fp);

$fp = fopen($oriFile, "r");
$fstat = fstat($fp);
$oriFileTime = $fstat['ctime'];
fclose($fp);

if (is_dir($oriPath . "/thumbs/")) {
$array1 = $array2 = array();
if ($dh = opendir($oriPath . "/thumbs/")) {
while (($file = readdir($dh)) !== false) {
$array1[] = $file;
}
closedir($dh);
}
if ($dh = opendir($oriPath . "/")) {
while (($file = readdir($dh)) !== false) {
$array2[] = $file;
}
closedir($dh);
}
$array_diff = array_diff($array1, $array2);
foreach ($array_diff as $k => $v) {
if (is_file($oriPath . "/thumbs/" . $v)) @unlink($oriPath . "/thumbs/" . $v);
}
}

$thmFileSize = getimagesize($thmFile);

if ($thmWidth == $thmFileSize[0] && $thmHeight == $thmFileSize[1]) { // 썸네일 갱신 불필요
if ($thmFileTime > $oriFileTime) {
$thmSize = getimagesize($thmFile);
$thmFilePrt = "<img src=\"".$thmFile."\" width=\"".$thmSize[0]."\" height=\"".$thmSize[1]."\" border=\"0\" alt=\"".$thmAlt."\" />";
return $thmFilePrt;
}
}

}

@unlink($thmFile);
@mkdir($thmPath);
@chmod($thmPath, 0707);

if ($widthRate < $heightRate) {
$tempWidth = (int)($oriWidth * $heightRate);
$tempHeight = $thmHeight;
} else {
$tempWidth = $thmWidth;
$tempHeight = (int)($oriHeight * $widthRate);
}

if ($tempWidth == "") $tempWidth = $thmWidth;
if ($tempHeight == "") $tempHeight = $thmHeight;

switch($oriType) {
case(1) :
if(function_exists('imagecreateFromGif')) $tempImage = imagecreateFromGif($oriFile);
break;
case(2) :
if(function_exists('imagecreateFromJpeg')) $tempImage = imagecreateFromJpeg($oriFile);
break;
case(3) :
if(function_exists('imagecreateFromPng')) $tempImage = imagecreateFromPng($oriFile);
break;
}

if ($tempImage) {
if (function_exists('imagecreatetruecolor')) {
$tempCanvas = imagecreatetruecolor($thmWidth, $thmHeight);
} else {
$tempCanvas = imagecreate($thmWidth, $thmHeight);
}

if (function_exists('imagecopyresampled')) {
imagecopyresampled($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
} else {
imagecopyresized($tempCanvas, $tempImage, 0, 0, 0, 0, $tempWidth, $tempHeight, ImageSX($tempImage), ImageSY($tempImage));
}
ImageDestroy($tempImage);
ImageJpeg($tempCanvas, $thmFile, 100);
ImageDestroy($tempCanvas);
unset($tempImage, $tempCanvas);
}

$thmFilePrt = "<img src=\"{$thmFile}\" width=\"{$thmWidth}\" height=\"{$thmHeight}\" border=\"0\" alt=\"{$thmAlt}\" />";

return $thmFilePrt;
}
}
?>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 1개

makeThumbs($oriPath, $oriFileName) 파일경로와 파일명만 넣어보세요

지정이 안되어 있을때 알아서 섬네일이 만들어지네요

아 그리고 파일리턴값을 저장해서 섬네일을 직접불러오셔야 겠네요

디비 저장하는 로직이 없으니..

게시글 목록

번호 제목
284508
284499
284492
284490
284484
284481
284478
284476
284474
284472
284470
284458
284457
284454
284453
284447
284446
284444
284441
284440