시작페이지로 즐겨찾기추가
로그인
회원가입 l 출석체크 l 마이페이지 l CGIMALL
happycgi
자료실 사이트등록 랭킹100 프로그램리뷰 관리자추천자료 초보가이드
커뮤니티
전체 펼쳐보기
퀵메뉴링크 jquery , CSS , PHP , Javascript , 무료폰트 , ASP
상세검색
 > PHP > PHP 소스창고 > 웹 유틸리티 > 썸네일 생성클래스 상세정보
사이트등록
클라우드태그
javascript
PHP
css
asp
HTML
jquery
MYSQL
API
image
Mobile
slide
게시판
메뉴
현재접속자 152 새로고침
썸네일 생성클래스
소스통계정보 오류신고 및 문의
해피팀
네티즌
트위터로 보내기 페이스북으로 보내기 네이버로공유
소스분류 웹 유틸리티
다운로드 횟수 728 회
간단설명 class.Thumbnail.php (썸네일 생성클래스) 1.0
평가하기 훌륭함 매우좋음 좋음 괜찮음 보통 별로
소스다운로드 데모 미리보기가 없습니다 스크랩하기
==============
소 개 (INTRO)
==============

GD 라이브러리를 이용하여 이미지를 축소 확대 시키는 클래스 입니다.
갤러리 프로그램에서 별도의 프로그램구동없이 썸네일을 만들어 주어야 할때
유용하게 쓰일수 있을거 같습니다.


==============
라이센스
==============

GNU GPL

==============
설치환경
==============

GD 라이브러리

=============
설 치
=============

파일을 업로드 하는것만으로 설치작업은 완료됩니다.

사용법은 아래와 같습니다.

include("../class.Thumbnail.php"); <-- 썸네일을 만드는 클래스파일 경로지정
$tn_image = new Thumbnail("sample.gif", 0, 0, 25); <-- 객체 생성

sample.gif : 이미지 파일명
0 : 최대 썸네일 폭 (옵션)
0 : 최대 썸네일 길이 (옵션)
25 : 퍼센트 (옵션)

$tn_image->show(); <-- 이미지 파일 출력

==============
주 의
==============

본 클래스를 사용하기 위해서는 GD 라이브러리가 사용가능 해야 하며
jpg,gif,png 의 이미지 화일중 GD 에서 지원하는 포멧형식만 사용가능
합니다.

확인방법은 아래 줄을 새파일에 적은후에 웹브라우저로 보면 PHP 가
지원하는 모듈을 볼수 있습니다.





==============
소 스
==============
소스는 다운로드 받으면 동일한 소스와 예제파일이 있습니다.

/*
* class.Thumbnail.php
*
* Copyright (C) 2001 Hidayet Dogan (hdogan@bilcag.net)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/

class Thumbnail {
var $errmsg = "";
var $error = false;
var $format = "";
var $file = "";
var $max_width = 0;
var $max_height = 0;
var $percent = 0;

function Thumbnail($file, $max_width = 0, $max_height = 0, $percent = 0) {
if (!file_exists($file)) {
$this->errmsg = "File doesn``t exists";
$this->error = true;
}
else if (!is_readable($file)) {
$this->errmsg = "File is not readable";
$this->error = true;
}

if (strstr(strtolower($file), ".gif"))
$this->format = "GIF";
else if (strstr(strtolower($file), ".jpg") ||
strstr(strtolower($file), ".jpeg"))
$this->format = "JPEG";
else if (strstr(strtolower($file), ".png"))
$this->format = "PNG";
else {
$this->errmsg = "Unknown file format";
$this->error = true;
}

if ($max_width == 0 && $max_height == 0 && $percent == 0)
$percent = 100;

$this->max_width = $max_width;
$this->max_height = $max_height;
$this->percent = $percent;
$this->file = $file;
}

function calc_width($width, $height) {
$new_width = $this->max_width;
$new_wp = (100 * $new_width) / $width;
$new_height = ($height * $new_wp) / 100;
return array($new_width, $new_height);
}

function calc_height($width, $height) {
$new_height = $this->max_height;
$new_hp = (100 * $new_height) / $height;
$new_width = ($width * $new_hp) / 100;
return array($new_width, $new_height);
}

function calc_percent($width, $height) {
$new_width = ($width * $this->percent) / 100;
$new_height = ($height * $this->percent) / 100;
return array($new_width, $new_height);
}

function return_value($array) {
$array[0] = intval($array[0]);
$array[1] = intval($array[1]);
return $array;
}

function calc_image_size($width, $height) {
$new_size = array($width, $height);

if ($this->max_width > 0) {
$new_size = $this->calc_width($width, $height);

if ($this->max_height > 0) {
if ($new_size[1] > $this->max_height)
$new_size = $this->calc_height($new_size[0], $new_size[1]);
}

return $this->return_value($new_size);
}

if ($this->max_height > 0) {
$new_size = $this->calc_height($width, $height);
return $this->return_value($new_size);
}

if ($this->percent > 0) {
$new_size = $this->calc_percent($width, $height);
return $this->return_value($new_size);
}
}

function show_error_image() {
header("Content-type: image/png");
$err_img = ImageCreate(220, 25);
$bg_color = ImageColorAllocate($err_img, 0, 0, 0);
$fg_color1 = ImageColorAllocate($err_img, 255, 255, 255);
$fg_color2 = ImageColorAllocate($err_img, 255, 0, 0);
ImageString($err_img, 3, 6, 6, "ERROR:", $fg_color2);
ImageString($err_img, 3, 55, 6, $this->errmsg, $fg_color1);
ImagePng($err_img);
ImageDestroy($err_img);
}

function show() {
if ($this->error) {
$this->show_error_image();
return;
}

$size = GetImageSize($this->file);
$new_size = $this->calc_image_size($size[0], $size[1]);
$new_image = ImageCreate($new_size[0], $new_size[1]);

switch ($this->format) {
case "GIF":
$old_image = ImageCreateFromGif($this->file);
break;
case "JPEG":
$old_image = ImageCreateFromJpeg($this->file);
break;
case "PNG":
$old_image = ImageCreateFromPng($this->file);
break;
}

ImageCopyResized($new_image, $old_image, 0, 0, 0, 0, $new_size[0], $new_size[1], $size[0], $size[1]);

switch ($this->format) {
case "GIF":
header("Content-type: image/gif");
ImageGif($new_image);
break;
case "JPEG":
header("Content-type: image/jpeg");
ImageJpeg($new_image);
break;
case "PNG":
header("Content-type: image/png");
ImagePng($new_image);
break;
}

ImageDestroy($new_image);
ImageDestroy($old_image);
return;
}
}
?>

자료출처 http://www.codelib.co.kr
네티즌 의견   이용하신 자료의 후기를 자유롭게 작성하세요. (상업적인 광고 및 도배성 글 등은 사전통보없이 삭제될 수 있습니다.)
내용 아이디 의견남기기
등록된 의견이 없습니다.
1
이름
내용
:네맞아요: :화나는군요: :잠와: :우울해: :이건아냐: :왕하하: 왕웃음~ 놀램~
평가하기 훌륭함 매우좋음 좋음 괜찮음 보통 별로
도배방지키
 26262664 보이는 도배방지키를 입력하세요.