我只想知道是否可以获取不同图像的尺寸,并为这些图片创建固定的缩略图尺寸测量而不会丢失其精确的高宽比。为不同尺寸的图像创建固定的缩略图尺寸
到目前为止,我已经使这些:
- 调整不同的图像
- 保持它们的纵横比
- 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