이미지 썸네일을 사용할때 생성하는 코드 > 그누4 팁자료실

그누4 팁자료실

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

이미지 썸네일을 사용할때 생성하는 코드 정보

이미지 썸네일을 사용할때 생성하는 코드

본문

----------------------------------------------------------------------------
lib/thumbnail.lib.php
----------------------------------------------------------------------------
<?
@ini_set("memory_limit", "32M");

function thumbnail($dir, $file, $width, $height, $is_create=false) {
    global $g4;

    $thumb_file = $dir . "/" . $width . "x" . $height . "_" . $file;
    $thumb_time = @filemtime($thumb_file);
    $source_file = $dir . "/" . $file;
    $source_time = @filemtime($source_file);
    if (@file_exists($thumb_file)) {
        if ($is_create == false && $source_time < $thumb_time) {
            return $thumb_file;
        }
    }

    $size = @getimagesize($source_file);
    // 이미지 파일이 없거나 아님
    if (!$size[0]) {
        if (!$height) $height = $width;
        $thumb_file = $dir . "/" . $width . "x" . $height . "_noimg.gif";
        $target = imagecreate($width, $height);      
        imagecolorallocate($target, 250, 250, 250);
        imagecopy($target, $target, 0, 0, 0, 0, $width, $height);
        imagegif($target, $thumb_file, 100);
        @chmod($thumb_file, 0606); // 추후 삭제를 위하여 파일모드 변경
        return $thumb_file;
    }

    $is_imagecopyresampled = false;
    $is_large = false;

    if ($size[2] == 1)
        $source = imagecreatefromgif($source_file);
    else if ($size[2] == 2)
        $source = imagecreatefromjpeg($source_file);
    else if ($size[2] == 3)
        $source = imagecreatefrompng($source_file);

    if ($width) {
        $x = $width;
        if ($height) {
            $y = $height;
            $rate = $x / $size[0];
            $tmp_y = (int)($size[1] * $rate);
            if ($tmp_y > $y) {
                $target = imagecreatetruecolor($x, $y);
                $tmp_target = imagecreatetruecolor($x, $tmp_y);
                imagecopyresampled($tmp_target, $source, 0, 0, 0, 0, $x, $tmp_y, $size[0], $size[1]);
                imagecopy($target, $tmp_target, 0, 0, 0, 0, $x, $y);
            } else {
                $target = imagecreatetruecolor($x, $tmp_y);
                imagecopyresampled($target, $source, 0, 0, 0, 0, $x, $tmp_y, $size[0], $size[1]);
            }
        } else {
            $rate = $x / $size[0];
            $tmp_y = (int)($size[1] * $rate);
            $target = imagecreatetruecolor($x, $tmp_y);
            imagecopyresampled($target, $source, 0, 0, 0, 0, $x, $tmp_y, $size[0], $size[1]);
        }
    }

    if ($size[2] == 1)
        imagegif($target, $thumb_file, 100);
    else if ($size[2] == 2)
        imagejpeg($target, $thumb_file, 100);
    else if ($size[2] == 3)
        imagepng($target, $thumb_file, 100);
    @chmod($thumb_file, 0606); // 추후 삭제를 위하여 파일모드 변경
    return $thumb_file;
}
?>
----------------------------------------------------------------------------




사용법 :

include_once("$g4[path]/lib/thumbnail.lib.php");

$img_src = thumbnail("폴더명", "파일명", 이미지폭, 이미지높이);
echo "<img src='$img_src' />";

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

추천
4

댓글 8개

스킨일 경우
delete.skin.php
생성
$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb'; //썸네일 폴더
@unlink("$thumb_path/$wr_id"); //썸네일 파일명
이렇게 작업하시면 됩니다
delete.skin.php
delete_all.skin.php
write_update.skin.php

이거 세가지 서누니님이 말한 형식(!!) 되로 맞게끔 다 넣으세요 그럼 모든 경우 다 썸네일 같이 움직입니다.
전체 45 |RSS
그누4 팁자료실 내용 검색

회원로그인

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