PHP’de Resim Küçültme

<?php
function resimkucult($filename1)

  {

    $image = $filename1;

 

    $max_width = 600;

    $max_height = 450;

 

    $size = GetImageSize($image);

    $width = $size[0];

    $height = $size[1];

 

    $x_ratio = $max_width / $width;

    $y_ratio = $max_height / $height;

 

    if (($height <= $max_height) && ($width <= $max_width))

    {

      $tn_height = $height;

      $tn_width = $width;

    }

    elseif (($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;

    }

 

    switch ($size['mime'])

    {

      case 'image/gif':

      {

        $src = ImageCreateFromGif($image);

        break;

      }

      case 'image/jpeg':

      {

        $src = ImageCreateFromJpeg($image);

        break;

      }

      case 'image/png':

      {

        $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: ' . $size['mime']);

 

    ImageJpeg($dst, $image);

    ImageDestroy($src);

    ImageDestroy($dst);

  }
  resimkucult("resim.jpg");    //burayı doğru yazın adresi yazarken dizin adı ve dosya adı doğru olsun
?>

Be the first to comment

Leave a Reply

Your email address will not be published.


*