그누5 썸네일엔진을 그누4에 적용시킬방법 없을까요?? 채택완료
D2BDesign
11년 전
조회 8,279
<div><div>function thumbnail($filename, $source_path, $target_path, $thumb_width, $thumb_height, $is_create, $is_crop=false, $crop_mode='center', $is_sharpen=true, $um_value='80/0.5/3')</div>
<div>{</div>
<div> global $g5;</div>
<div>
</div>
<div> if(!$thumb_width && !$thumb_height)</div>
<div> return;</div>
<div>
</div>
<div> $thumb_filename = preg_replace("/\.[^\.]+$/i", "", $filename); // 확장자제거</div>
<div> $thumb_file = "$target_path/thumb-{$thumb_filename}_{$thumb_width}x{$thumb_height}.jpg";</div>
<div> $source_file = "$source_path/$filename";</div>
<div>
</div>
<div> if(!is_file($source_file)) // 원본 파일이 없다면</div>
<div> return;</div>
<div>
</div>
<div> $size = @getimagesize($source_file);</div>
<div> if($size[2] < 1 || $size[2] > 3) // gif, jpg, png 에 대해서만 적용</div>
<div> return;</div>
<div>
</div>
<div> if (!is_dir($target_path)) {</div>
<div> @mkdir($target_path, G5_DIR_PERMISSION);</div>
<div> @chmod($target_path, G5_DIR_PERMISSION);</div>
<div> }</div>
<div>
</div>
<div> // Animated GIF는 썸네일 생성하지 않음</div>
<div> if($size[2] == 1) {</div>
<div> if(is_animated_gif($source_file))</div>
<div> return basename($source_file);</div>
<div> }</div>
<div>
</div>
<div> $thumb_time = @filemtime($thumb_file);</div>
<div> $source_time = @filemtime($source_file);</div>
<div>
</div>
<div> if (file_exists($thumb_file)) {</div>
<div> if ($is_create == false && $source_time < $thumb_time) {</div>
<div> return basename($thumb_file);</div>
<div> }</div>
<div> }</div>
<div>
</div>
<div> // 원본파일의 GD 이미지 생성</div>
<div> $src = null;</div>
<div> if ($size[2] == 1) {</div>
<div> $src = imagecreatefromgif($source_file);</div>
<div> } else if ($size[2] == 2) {</div>
<div> $src = imagecreatefromjpeg($source_file);</div>
<div> } else if ($size[2] == 3) {</div>
<div> $src = imagecreatefrompng($source_file);</div>
<div> } else {</div>
<div> return;</div>
<div> }</div>
<div>
</div>
<div> if(!$src)</div>
<div> return;</div>
<div>
</div>
<div> $is_large = true;</div>
<div> // width, height 설정</div>
<div> if($thumb_width) {</div>
<div> if(!$thumb_height) {</div>
<div> $thumb_height = round(($thumb_width * $size[1]) / $size[0]);</div>
<div> } else {</div>
<div> if($size[0] < $thumb_width || $size[1] < $thumb_height)</div>
<div> $is_large = false;</div>
<div> }</div>
<div> } else {</div>
<div> if($thumb_height) {</div>
<div> $thumb_width = round(($thumb_height * $size[0]) / $size[1]);</div>
<div> }</div>
<div> }</div>
<div>
</div>
<div> $dst_x = 0;</div>
<div> $dst_y = 0;</div>
<div> $src_x = 0;</div>
<div> $src_y = 0;</div>
<div> $dst_w = $thumb_width;</div>
<div> $dst_h = $thumb_height;</div>
<div> $src_w = $size[0];</div>
<div> $src_h = $size[1];</div>
<div>
</div>
<div> $ratio = $dst_h / $dst_w;</div>
<div>
</div>
<div> if($is_large) {</div>
<div> // 크롭처리</div>
<div> if($is_crop) {</div>
<div> switch($crop_mode)</div>
<div> {</div>
<div> case 'center':</div>
<div> if($size[1] / $size[0] >= $ratio) {</div>
<div> $src_h = round($src_w * $ratio);</div>
<div> $src_y = round(($size[1] - $src_h) / 2);</div>
<div> } else {</div>
<div> $src_w = round($size[1] / $ratio);</div>
<div> $src_x = round(($size[0] - $src_w) / 2);</div>
<div> }</div>
<div> break;</div>
<div> default:</div>
<div> if($size[1] / $size[0] >= $ratio) {</div>
<div> $src_h = round($src_w * $ratio);</div>
<div> } else {</div>
<div> $src_w = round($size[1] / $ratio);</div>
<div> }</div>
<div> break;</div>
<div> }</div>
<div> }</div>
<div>
</div>
<div> $dst = imagecreatetruecolor($dst_w, $dst_h);</div>
<div> } else {</div>
<div> $dst = imagecreatetruecolor($dst_w, $dst_h);</div>
<div>
</div>
<div> if($src_w < $dst_w) {</div>
<div> if($src_h >= $dst_h) {</div>
<div> $dst_x = round(($dst_w - $src_w) / 2);</div>
<div> $src_h = $dst_h;</div>
<div> } else {</div>
<div> $dst_x = round(($dst_w - $src_w) / 2);</div>
<div> $dst_y = round(($dst_h - $src_h) / 2);</div>
<div> $dst_w = $src_w;</div>
<div> $dst_h = $src_h;</div>
<div> }</div>
<div> } else {</div>
<div> if($src_h < $dst_h) {</div>
<div> $dst_y = round(($dst_h - $src_h) / 2);</div>
<div> $dst_h = $src_h;</div>
<div> $src_w = $dst_w;</div>
<div> }</div>
<div> }</div>
<div>
</div>
<div> $bgcolor = imagecolorallocate($dst, 255, 255, 255); // 배경색</div>
<div> imagefill($dst, 0, 0, $bgcolor);</div>
<div> }</div>
<div>
</div>
<div> imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);</div>
<div>
</div>
<div> // sharpen 적용</div>
<div> if($is_sharpen && $is_large) {</div>
<div> $val = explode('/', $um_value);</div>
<div> UnsharpMask($dst, $val[0], $val[1], $val[2]);</div>
<div> }</div>
<div>
</div>
<div> imagejpeg($dst, $thumb_file, 90);</div>
<div> chmod($thumb_file, G5_FILE_PERMISSION); // 추후 삭제를 위하여 파일모드 변경</div>
<div>
</div>
<div> imagedestroy($src);</div>
<div> imagedestroy($dst);</div>
<div>
</div>
<div> return basename($thumb_file);</div>
<div>}</div>
<div>
</div>
<div>function UnsharpMask($img, $amount, $radius, $threshold) {</div>
<div>
</div>
<div>/*</div>
<div>출처 : <a href="http://vikjavev.no/computing/ump.php" target="_blank" rel="noopener noreferrer">http://vikjavev.no/computing/ump.php</a></div>
<div>New:</div>
<div>- In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.</div>
<div>- From version 2 (July 17 2006) the script uses the imageconvolution function in PHP</div>
<div>version >= 5.1, which improves the performance considerably.</div>
<div>
</div>
<div>
</div>
<div>Unsharp masking is a traditional darkroom technique that has proven very suitable for</div>
<div>digital imaging. The principle of unsharp masking is to create a blurred copy of the image</div>
<div>and compare it to the underlying original. The difference in colour values</div>
<div>between the two images is greatest for the pixels near sharp edges. When this</div>
<div>difference is subtracted from the original image, the edges will be</div>
<div>accentuated.</div>
<div>
</div>
<div>The Amount parameter simply says how much of the effect you want. 100 is 'normal'.</div>
<div>Radius is the radius of the blurring circle of the mask. 'Threshold' is the least</div>
<div>difference in colour values that is allowed between the original and the mask. In practice</div>
<div>this means that low-contrast areas of the picture are left unrendered whereas edges</div>
<div>are treated normally. This is good for pictures of e.g. skin or blue skies.</div>
<div>
</div>
<div>Any suggenstions for improvement of the algorithm, expecially regarding the speed</div>
<div>and the roundoff errors in the Gaussian blur process, are welcome.</div>
<div>
</div>
<div>*/</div>
<div>
</div>
<div>////////////////////////////////////////////////////////////////////////////////////////////////</div>
<div>////</div>
<div>//// Unsharp Mask for PHP - version 2.1.1</div>
<div>////</div>
<div>//// Unsharp mask algorithm by Torstein Hønsi 2003-07.</div>
<div>//// thoensi_at_netcom_dot_no.</div>
<div>//// Please leave this notice.</div>
<div>////</div>
<div>///////////////////////////////////////////////////////////////////////////////////////////////</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div> // $img is an image that is already created within php using</div>
<div> // imgcreatetruecolor. No url! $img must be a truecolor image.</div>
<div>
</div>
<div> // Attempt to calibrate the parameters to Photoshop:</div>
<div> if ($amount > 500) $amount = 500;</div>
<div> $amount = $amount * 0.016;</div>
<div> if ($radius > 50) $radius = 50;</div>
<div> $radius = $radius * 2;</div>
<div> if ($threshold > 255) $threshold = 255;</div>
<div>
</div>
<div> $radius = abs(round($radius)); // Only integers make sense.</div>
<div> if ($radius == 0) {</div>
<div> return $img; imagedestroy($img); break; }</div>
<div> $w = imagesx($img); $h = imagesy($img);</div>
<div> $imgCanvas = imagecreatetruecolor($w, $h);</div>
<div> $imgBlur = imagecreatetruecolor($w, $h);</div>
<div>
</div>
<div>
</div>
<div> // Gaussian blur matrix:</div>
<div> //</div>
<div> // 1 2 1</div>
<div> // 2 4 2</div>
<div> // 1 2 1</div>
<div> //</div>
<div> //////////////////////////////////////////////////</div>
<div>
</div>
<div>
</div>
<div> if (function_exists('imageconvolution')) { // PHP >= 5.1</div>
<div> $matrix = array(</div>
<div> array( 1, 2, 1 ),</div>
<div> array( 2, 4, 2 ),</div>
<div> array( 1, 2, 1 )</div>
<div> );</div>
<div> $divisor = array_sum(array_map('array_sum', $matrix));</div>
<div> $offset = 0;</div>
<div>
</div>
<div> imagecopy ($imgBlur, $img, 0, 0, 0, 0, $w, $h);</div>
<div> imageconvolution($imgBlur, $matrix, $divisor, $offset);</div>
<div> }</div>
<div> else {</div>
<div>
</div>
<div> // Move copies of the image around one pixel at the time and merge them with weight</div>
<div> // according to the matrix. The same matrix is simply repeated for higher radii.</div>
<div> for ($i = 0; $i < $radius; $i++) {</div>
<div> imagecopy ($imgBlur, $img, 0, 0, 1, 0, $w - 1, $h); // left</div>
<div> imagecopymerge ($imgBlur, $img, 1, 0, 0, 0, $w, $h, 50); // right</div>
<div> imagecopymerge ($imgBlur, $img, 0, 0, 0, 0, $w, $h, 50); // center</div>
<div> imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);</div>
<div>
</div>
<div> imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up</div>
<div> imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down</div>
<div> }</div>
<div> }</div>
<div>
</div>
<div> if($threshold>0){</div>
<div> // Calculate the difference between the blurred pixels and the original</div>
<div> // and set the pixels</div>
<div> for ($x = 0; $x < $w-1; $x++) { // each row</div>
<div> for ($y = 0; $y < $h; $y++) { // each pixel</div>
<div>
</div>
<div> $rgbOrig = ImageColorAt($img, $x, $y);</div>
<div> $rOrig = (($rgbOrig >> 16) & 0xFF);</div>
<div> $gOrig = (($rgbOrig >> 8) & 0xFF);</div>
<div> $bOrig = ($rgbOrig & 0xFF);</div>
<div>
</div>
<div> $rgbBlur = ImageColorAt($imgBlur, $x, $y);</div>
<div>
</div>
<div> $rBlur = (($rgbBlur >> 16) & 0xFF);</div>
<div> $gBlur = (($rgbBlur >> 8) & 0xFF);</div>
<div> $bBlur = ($rgbBlur & 0xFF);</div>
<div>
</div>
<div> // When the masked pixels differ less from the original</div>
<div> // than the threshold specifies, they are set to their original value.</div>
<div> $rNew = (abs($rOrig - $rBlur) >= $threshold)</div>
<div> ? max(0, min(255, ($amount * ($rOrig - $rBlur)) + $rOrig))</div>
<div> : $rOrig;</div>
<div> $gNew = (abs($gOrig - $gBlur) >= $threshold)</div>
<div> ? max(0, min(255, ($amount * ($gOrig - $gBlur)) + $gOrig))</div>
<div> : $gOrig;</div>
<div> $bNew = (abs($bOrig - $bBlur) >= $threshold)</div>
<div> ? max(0, min(255, ($amount * ($bOrig - $bBlur)) + $bOrig))</div>
<div> : $bOrig;</div>
<div>
</div>
<div>
</div>
<div>
</div>
<div> if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {</div>
<div> $pixCol = ImageColorAllocate($img, $rNew, $gNew, $bNew);</div>
<div> ImageSetPixel($img, $x, $y, $pixCol);</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div> else{</div>
<div> for ($x = 0; $x < $w; $x++) { // each row</div>
<div> for ($y = 0; $y < $h; $y++) { // each pixel</div>
<div> $rgbOrig = ImageColorAt($img, $x, $y);</div>
<div> $rOrig = (($rgbOrig >> 16) & 0xFF);</div>
<div> $gOrig = (($rgbOrig >> 8) & 0xFF);</div>
<div> $bOrig = ($rgbOrig & 0xFF);</div>
<div>
</div>
<div> $rgbBlur = ImageColorAt($imgBlur, $x, $y);</div>
<div>
</div>
<div> $rBlur = (($rgbBlur >> 16) & 0xFF);</div>
<div> $gBlur = (($rgbBlur >> 8) & 0xFF);</div>
<div> $bBlur = ($rgbBlur & 0xFF);</div>
<div>
</div>
<div> $rNew = ($amount * ($rOrig - $rBlur)) + $rOrig;</div>
<div> if($rNew>255){$rNew=255;}</div>
<div> elseif($rNew<0){$rNew=0;}</div>
<div> $gNew = ($amount * ($gOrig - $gBlur)) + $gOrig;</div>
<div> if($gNew>255){$gNew=255;}</div>
<div> elseif($gNew<0){$gNew=0;}</div>
<div> $bNew = ($amount * ($bOrig - $bBlur)) + $bOrig;</div>
<div> if($bNew>255){$bNew=255;}</div>
<div> elseif($bNew<0){$bNew=0;}</div>
<div> $rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;</div>
<div> ImageSetPixel($img, $x, $y, $rgbNew);</div>
<div> }</div>
<div> }</div>
<div> }</div>
<div> imagedestroy($imgCanvas);</div>
<div> imagedestroy($imgBlur);</div>
<div>
</div>
<div> return true;</div>
<div>
</div>
<div>}</div>
<div>
그누5에 기본으로 썸네일엔진이 들어가있는데 사용해보니 너무 좋은것같아서 혹시 그누4에 적용시킬 방법이 없을까해서 질문드립니다.
썸네일만 생성하면되기에 전체는 필요없을듯하고 상단코드만 사용하면 될것같이 보이는데 어떻게 수정해줘야할지 전혀 모르겠네요..ㅠㅠ
도움 부탁드려요~
댓글을 작성하려면 로그인이 필요합니다.
답변 3개
채택된 답변
+20 포인트
11년 전
스킨파일 참고하시면 될것 같습니다. 우선 상단에 아래처럼 파일불러오고
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
이렇게 사용하던가
get_view_thumbnail($view['file'][$i]['view']);
이렇게 사용하면 될것 같습니다.
get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], 가로크기, 세로크기);
앗! 그전에 thumbnail.lib.php 파일을 열어 그누4 변수로 바꿔줘야겠네요
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인