Код:# Создаем уменьшенные фото
function create_small_photo ($pic,$width=150,$height=150) {
$img_path = $_SERVER["DOCUMENT_ROOT"].$pic;
$ext = strtolower(substr(strrchr($pic, "."),1));
if (file_exists($img_path) && ($ext == 'jpg' || $ext == 'jpeg')) {
$img = @imagecreatefromjpeg($img_path) or die("Cannot Initialize new GD image stream for JPEG");;
}
if (file_exists($img_path) && $ext == 'gif') {
$img = @imagecreatefromgif($img_path) or die("Cannot Initialize new GD image stream for GIF");;
}
if ($img) {
$w = imagesx($img);
$h = imagesy($img);
$scale = min($width/$w, $height/$h);
if ($scale < 1) {
$new_width = floor($scale*$w);
$new_height = floor($scale*$h);
$img2 = @imagecreatetruecolor($new_width, $new_height) or die("Cannot Initialize new GD image stream");;
imagefill($img2, 0, 0, 0xFFFFFF);
imagecopyresampled($img2, $img, 0, 0, 0, 0,
$new_width, $new_height, $w, $h);
imagedestroy($img);
$img = $img2;
}
}
$pic_name=str_replace("/netcat_files/","",$pic);
$tmpfname = $_SERVER["DOCUMENT_ROOT"]."/netcat_files/".$pic_name;
imagejpeg($img,$tmpfname);
}