에디터로 올린 이미지도 썸네일 생성하기

에디터로 올린 이미지도 썸네일 생성하기

QA

에디터로 올린 이미지도 썸네일 생성하기

본문

아래코드로 된 가로세로 짤리는 썸네일 생성 갤러리 게시판을 사용하고 있습니다.
에디터로 올린 이미지도 썸네일을 생성하도록 하고싶은데 어던 코드를 넣어야 할지 도통 감이 안와 질문 남김니다.
가로 세로가 지정한 크기대로 잘려서 썸네일 생성되는게 맘에들어 사용중인데 에디터로 올린 이미지가 말썽이네요

list.skin.php 썸네일 관련 반복 부분

 <? 
    for ($i=0; $i<count($list); $i++) { 
	
        $style = "";
        $list[$i][subject] = str_replace(" "," ",$list[$i][subject]);
		$image = $list[$i][file][0][file];

        $comment_cnt = "";
        if ($list[$i][comment_cnt]) 
           $comment_cnt = " <a href=\"{$list[$i][comment_href]}\"><span class='commentFont'>{$list[$i][comment_cnt]}</span></a>";

        $list[$i][name] = preg_replace("/<img /", "<img style='display:none;' ", $list[$i][name]);
        $list[$i][name] = preg_replace("/> <span/", "><span", $list[$i][name]);
        $list[$i][name] = preg_replace("/class='member'/", "", $list[$i][name]);
?>
  <div class="view view-third">
	<a href='<?=$list[$i][href]?>'><?=makeThumbs($g4[path]."/data/file/$bo_table", $list[$i][file][0][file], $board[bo_1], $board[bo_2])?></a>
	<div class="mask">
		<a href='<?=$list[$i][href]?>'><h2><?=$list[$i][subject]?></h2></a>
		<a href='<?=$list[$i][href]?>'><p><?=$list[$i][wr_content]?></p></a>
	</div>
<? if ($is_checkbox) echo "<input type=checkbox name=chk_wr_id[] value='{$list[$i][wr_id]}'>";?>
</div>
<? } ?>



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

답변을 작성하시기 전에 로그인 해주세요.
전체 1,534
QA 내용 검색

회원로그인

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