리자

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

----------------------------------------------------------------------------
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' />";

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

|

댓글 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

이거 세가지 서누니님이 말한 형식(!!) 되로 맞게끔 다 넣으세요 그럼 모든 경우 다 썸네일 같이 움직입니다.
위 세가지 파일은 다음 링크 참고하십시오.
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=23606
감사합니다.._(__)_
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누4 팁자료실

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

+
제목 글쓴이 날짜 조회
16년 전 조회 3,123
16년 전 조회 3,903
16년 전 조회 1.2만
16년 전 조회 2,185
16년 전 조회 8,205
16년 전 조회 9,395
17년 전 조회 4,956
17년 전 조회 3,489
17년 전 조회 4,682
17년 전 조회 6,234
17년 전 조회 2,759
17년 전 조회 2,750
17년 전 조회 2,232
17년 전 조회 4,343
17년 전 조회 2,747
17년 전 조회 4,631
17년 전 조회 6,083
17년 전 조회 6,062
17년 전 조회 1.2만
17년 전 조회 7,662
🐛 버그신고