$width) { // Вычисление пропорций $ratio = $w_src/$width; $w_dest = round($w_src/$ratio); $h_dest = round($h_src/$ratio); if ($h_dest > $height){ $ratio = $h_dest/$height; $w_dest = round($w_dest/$ratio); $h_dest = round($h_dest/$ratio); } } else { $w_dest = $w_src; $h_dest = $h_src; } //Пустая картинка $dest = imagecreatetruecolor($w_dest, $h_dest); if($ext=='.gif') { imagealphablending($src, false); $ct = @imagecolortransparent($src); $color_tran = @imagecolorsforindex($src, $ct); if($color_tran) { $ct2 = imagecolorexact($dest, $color_tran['red'], $color_tran['green'], $color_tran['blue']); imagefill($dest,0,0,$ct2); } /** * Определяем функцию, которой будет выполнен ресайз изображения */ $sResizeFunction = 'imagecopyresampled'; if(!function_exists($sResizeFunction)) $sResizeFunction = 'imagecopyresized'; if(isset($ct) and $ct!=-1) $sResizeFunction = 'imagecopyresized'; if(!@$sResizeFunction($dest,$src,0,0,0,0,$w_dest, $h_dest, $w_src, $h_src)) { imagedestroy($dest); return false; } imagesavealpha($dest, true); if(isset($ct2)) imagecolortransparent($dest, $ct2); } else { /** * Регулируем альфа-канал, если не указано обработное */ if($alfa) { @imagesavealpha($dest,true); @imagealphablending($dest,false); } if(!@imagecopyresampled($dest,$src,0,0,0,0,$w_dest, $h_dest, $w_src, $h_src)) { imagedestroy($dest); return false; } } if ($ext == '.jpg') { header("Content-type: image/jpeg"); imagejpeg($dest, $preview_dir.$new_filename, 90); imagejpeg($dest, null, 90); } elseif ($ext == '.gif') { header("Content-type: image/gif"); imagegif($dest, $preview_dir.$new_filename); imagegif($dest); } elseif ($ext == '.png') { header("Content-type: image/png"); imagepng($dest, $preview_dir.$new_filename); imagepng($dest); } imagedestroy($dest); imagedestroy($src); } ?>