<?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
); 
 } 
 
?>


블로그 이미지

하보니

하보니와 함께하는 phP 초보

댓글을 달아 주세요