이미지 썸네일을 사용할때 생성하는 코드 정보
이미지 썸네일을 사용할때 생성하는 코드
본문
----------------------------------------------------------------------------
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_all.skin.php
write_update.skin.php
이거 세가지 서누니님이 말한 형식(!!) 되로 맞게끔 다 넣으세요 그럼 모든 경우 다 썸네일 같이 움직입니다.
http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=23606

