<?PHP
function make_thumbnail($img$dest$thumb_size 130){

    
$currentimagesize getimagesize($img);
    
$width $currentimagesize[0];
    
$height$currentimagesize[1];

    
$size GetImageSize ($img);
    if(
$size[2] == '2'){
         
$type 'jpg';
    }elseif(
$size[2] == '3'){
        
$type 'png';
    }

    
copy($img$dest);

    
// make thumb
    
if ($width $thumb_size OR $height $thumb_size){
        if (
$width $height){
            
$thumbwidth $thumb_size;
            
$thumbheight $height * ($thumbwidth $width);
        }else{
            
$thumbheight $thumb_size;
            
$thumbwidth $width * ($thumbheight $height);
        }

        
$newsize intval($thumbwidth) . "x" intval($thumbheight) . "!";
        
exec("/usr/bin/mogrify -resize " $newsize .' '.$dest.' 2>&1'$exec_output$exec_retval);
    }

?>