php
PHP - 썸네일 생성 함수
썸네일은 큰 이미지를 손톱 크기로 만든다고 해서 썸네일(손톱 이미지)라 부릅니다.
<?php
// 썸네일 생성함수
// $mime = 1, gif
// 2, jpg
// 3, png
// 4, bmp
// $tmpfile = 실제 존재하는 그림파일 경로
// $src = 썸네일 생성할 경로
// $tmpsize = 기본값, 100
function thumbWrite($mime,$tmpfile,$src,$tmpsize){
if(!file_exists($tmpfile)){
return false;
}
if(!file_exists($src)){
return false;
}
if(!is_int($tmpsize) || ($tmpsize < 100)){
$tmpsize = 100;
}
$size = getimagesize($tmpfile,&$sizes);
if($size[0] >= $size[1]) {
$x = $tmpsize;
$y = (($tmpsize * $size[1])/$size[0]);
} else {
$y = $tmpsize;
$x = (($tmpsize * $size[0])/$size[1]);
}
if(function_exists('imagecreatefromgif') && ($mime === 1)) {
$tmpsrc = imagecreatefromgif($tmpfile);
$thumb = imagecreatetruecolor($x,$y);
imagecopyresized(
$thumb, $tmpsrc,0,0,0,0,$x,$y,
imagesx($tmpsrc),imagesy($tmpsrc)
);
imagegif($thumb,$src);
} elseif(function_exists('imagecreatefromjpeg') && ($mime === 2)) {
$tmpsrc = imagecreatefromjpeg($tmpfile);
$thumb = imagecreatetruecolor($x,$y);
imagecopyresized(
$thumb,$tmpsrc,0,0,0,0,$x,$y,
imagesx($tmpsrc),imagesy($tmpsrc)
);
imagejpeg($thumb,$src);
} elseif(function_exists('imagecreatefrompng') && ($mime === 3)) {
$tmpsrc = imagecreatefrompng($tmpfile);
$thumb = imagecreatetruecolor($x,$y);
imagecopyresized(
$thumb,$tmpsrc,0,0,0,0,$x,$y,
imagesx($tmpsrc),imagesy($tmpsrc)
);
imagepng($thumb,$src);
} elseif(function_exists('imagecreatefromwbmp') && ($mime === 4)) {
$tmpsrc = imagecreatefromwbmp($tmpfile);
$thumb = imagecreatetruecolor($x,$y);
imagecopyresized(
$thumb,$tmpsrc,0,0,0,0,$x,$y,
imagesx($tmpsrc),imagesy($tmpsrc)
);
imagewbmp($thumb,$src);
}
imagedestroy($thumb);
imagedestroy($tmpsrc);
}
?>
0 댓글