我只想知道是否可以獲取不同圖像的尺寸,併爲這些圖片創建固定的縮略圖尺寸測量而不會丟失其精確的高寬比。爲不同尺寸的圖像創建固定的縮略圖尺寸
到目前爲止,我已經使這些:
- 調整不同的圖像
- 保持它們的縱橫比
- NOT供給相同的尺寸(例如:100px-高度和寬度100px-)
下面是我與工作代碼:
<?php
require("dbinfo.php");
$allPhotosQuery = mysql_query (" SELECT * FROM `placesImages` ");
while ($allPhotosArray = mysql_fetch_assoc ($allPhotosQuery))
{
$filename= $allPhotosArray['fileName'];
$placeId = $allPhotosArray['placeId'];
$imagePath = "placesImages/" . $placeId . "/" . $filename;
$imageSize = getimagesize($imagePath);
$imageWidth = $imageSize[0];
$imageHeight = $imageSize[1];
$newSize = ($imageWidth + $imageHeight)/($imageWidth*($imageHeight/45));
$newHeight = $imageHeight * $newSize;
$newWidth = $imageWidth * $newSize;
echo "<img src='".$imagePath."' width='".$newWidth."' height='".$newHeight."' />";
}
?>
我相信,只有設置寬度將自動設置正確的高度。唯一需要做的是確保圖像的高度永遠不會高於固定寬度,否則你會表或任何你正在使用的,被扭曲。 – dbf