PHP Bir Resmin Istenilen Boyutlarda Gösterilmesi

  • Konbuyu başlatan Eqe
  • Başlangıç tarihi
E

Eqe

Guest
PHP- Kodu:
//Resim boyutları tanımlanıyor.

$maxWidth=100;

$maxHeight=80;


$imagename="/images/image_13_1.jpg";

// Orjinal resmin boyutları bulunuyor.

list($width, $height) = getimagesize($imagename);


// Oranlar bulunuyor.

$xRatio = $maxWidth / $width;

$yRatio = $maxHeight / $height;


// Orjinal resim ile görüntülenmek istenilen resim boyutları arasında dönüşüm yapılıyor.

if ( ($width <= $maxWidth) && ($height <= $maxHeight) ) {

$newWidth = $width;

$newHeight = $height;

}

else if ((
$xRatio * $height) < $maxHeight) {

$newHeight = ceil($xRatio * $height);

$newWidth = $maxWidth;

}

else {

$newWidth = ceil($yRatio * $width);

$newHeight = $maxHeight;

}



// İstenilen boyuttaki resim gösteriliyor.

echo "<img src='".$imagename."' width='$newWidth' height='$newHeight'>";

?>





 
Üst
Alt