$height){ $need_ratio = $width/$newWidth; $n_width = $newWidth; $n_height = $height/$need_ratio; $ofset_y = ($newHeight - $n_height)/2; if($n_height>$newHeight){ $need_ratio = $height/$newHeight; $n_width = $width/$need_ratio; $n_height = $newHeight; $ofset_x = ($newWidth - $n_width)/2; $ofset_y = ($newHeight - $n_height)/2; } } else { $need_ratio = $height/$newHeight; $n_width = $width/$need_ratio; $n_height = $newHeight; $ofset_x = ($newWidth - $n_width)/2; if($n_width>$newWidth){ $need_ratio = $width/$newWidth; $n_width = $newWidth; $n_height = $height/$need_ratio; $ofset_y = ($newHeight - $n_height)/2; $ofset_x = ($newWidth - $n_width)/2; } } if($size[2]==IMAGETYPE_GIF){ $src = ImageCreateFromGif($image); } else if($size[2]==IMAGETYPE_JPEG){ $src = ImageCreateFromJpeg($image); } else { $src = ImageCreateFromPNG($image); } $dst = ImageCreateTrueColor($newWidth,$newHeight); $background_color = imagecolorallocate($dst, 255, 255, 255); imagefilledrectangle($dst, 0,0, $newWidth, $newHeight, $background_color); ImageCopyResized($dst, $src, $ofset_x, $ofset_y, 0, 0, $n_width,$n_height,$width,$height); if($size[2]==IMAGETYPE_GIF){ header("Content-type: image/gif"); ImageGif($dst); } else if($size[2]==IMAGETYPE_JPEG){ header("Content-type: image/jpeg"); ImageJpeg($dst, null, 100); } else { header("Content-type: image/png"); ImagePNG($dst); } ImageDestroy($src); ImageDestroy($dst); } $id = intval(htmlspecialchars($_GET["id"], ENT_QUOTES)); if(!$id) return; $path = $_SERVER['DOCUMENT_ROOT']; include ("$_SERVER[DOCUMENT_ROOT]/includes/page.php"); $page = new Page(); $page -> ConnectDB(); $result = mysql_query("SELECT picture FROM teatr_docs WHERE id='$id';"); mysql_close($page->db); if(!mysql_num_rows($result)) return; $row = mysql_fetch_object($result); if(isset($_GET["news"])){ $path = $path.'/files/photos/'.$row->picture; if(!file_exists($path)) return; $width = 120; $height = 120; } imageResize($path, $width, $height); ?>