View file znwap/mfoto.php

File size: 2.61Kb
<?php

error_reporting(0);
// размеры фото
$max_width = 100;
$max_height =100;
// id юзера
$fid=$_GET['id'];
if (file_exists("images/$fid.gif")) {
          $image="images/$fid.gif";
          $act='gif';
     }
     if (file_exists("images/$fid.jpg")) {
          $image="images/$fid.jpg";
          $act='jpg';
     }
     if (file_exists("images/$fid.png")) {
          $image="images/$fid.png";
          $act='png';
     }


if($act=="jpg"){
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
  $tn_width = $width;
  $tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
  $tn_height = ceil($x_ratio * $height);
  $tn_width = $max_width;
}
else {
  $tn_width = ceil($y_ratio * $width);
  $tn_height = $max_height;
}

$src = ImageCreateFromJpeg($image);
$dst = ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
    $tn_width,$tn_height,$width,$height);
header("Content-type: image/jpeg");
if($show=="full"){
ImageJpeg ($dst, null, 80);}else{ ImageJpeg ($dst, null, 40);}
ImageDestroy($src);
ImageDestroy($dst); }


if($act=="gif"){
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
  $tn_width = $width;
  $tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
  $tn_height = ceil($x_ratio * $height);
  $tn_width = $max_width;
}
else {
  $tn_width = ceil($y_ratio * $width);
  $tn_height = $max_height;
}

$src = ImageCreateFromGif($image);
$dst = ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
    $tn_width,$tn_height,$width,$height);
header("Content-type: image/gif");
ImageGif ($dst);
ImageDestroy($src);
ImageDestroy($dst); }

 if($act=="png"){
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
  $tn_width = $width;
  $tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
  $tn_height = ceil($x_ratio * $height);
  $tn_width = $max_width;
}
else {
  $tn_width = ceil($y_ratio * $width);
  $tn_height = $max_height;
}

$src = ImageCreateFromPng($image);
$dst = ImageCreateTrueColor($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
    $tn_width,$tn_height,$width,$height);
header("Content-type: image/png");
ImagePng ($dst);
ImageDestroy($src);
ImageDestroy($dst); }

?>