我只是想知道是否有可能获得不同的图像尺寸,并为这些图片创建固定的缩略图尺寸测量,而不会丢失其准确的纵横比。
到目前为止,我已经做了这些:
- 调整不同图像的大小
- 保持它们的纵横比
- 不提供相同的尺寸(例如: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."' />";
}
?>