Комментарии: 2
| 
 | 
 | 
 | 
  
<?php 
function img_thumb($imgfile, $imgthumb, $newwidth) 
{ 
    if (function_exists('imagecreate')) 
    { 
        $imginfo = getimagesize($imgfile); 
        if ($imginfo[2] > 3) 
        { 
            echo 'Недопустимый формат!'; 
            exit; 
        } 
        if ($imginfo[2] == 1) 
        { 
            if (!function_exists("imagecreatefromgif")) 
                return $imgfile; 
            $srcImage = imagecreatefromgif($imgfile); 
        } 
        if ($imginfo[2] == 2) 
        { 
            if (!function_exists("imagecreatefromjpeg")) 
                return $imgfile; 
            $srcImage = imagecreatefromjpeg($imgfile); 
        } 
        if ($imginfo[2] == 3) 
        { 
            if (!function_exists("imagecreatefrompng")) 
                return $imgfile; 
            $srcImage = imagecreatefrompng($imgfile); 
        } 
        if ($srcImage) 
        { 
            $srcWidth = $imginfo[0]; 
            $srcHeight = $imginfo[1]; 
            $ratioWidth = $srcWidth / $newwidth; 
            $destWidth = $newwidth; 
            $destHeight = $srcHeight / $ratioWidth; 
            $destImage = imagecreatetruecolor($destWidth, $destHeight); 
            imagealphablending($destImage, true); 
            imagealphablending($srcImage, false); 
            imagecopyresized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); 
            imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); 
            if ($imginfo[2] == 1) 
                imagegif($destImage, $imgthumb); 
            if ($imginfo[2] == 2) 
                imagejpeg($destImage, $imgthumb); 
            if ($imginfo[2] == 3) 
                imagepng($destImage, $imgthumb); 
            imagedestroy($srcImage); 
            imagedestroy($destImage); 
            return $imgthumb; 
        } else 
        { 
            return $imgfile; 
        } 
    } else 
    { 
        return $imgfile; 
    } 
} 
?>