在 php 中,我使用 php move_uploaded_file 函数将图像上传到数据库。现在,当我从数据库中获取图像时,我正在使用此代码获取图像
$result = mysql_query("SELECT * FROM "._DB_PREFIX_."storeimages WHERE `city_name`='".$_GET['details']."'");
while($row = mysql_fetch_array($result)){
echo '<div class="store-img">';
echo '<img class="store-image" src="storeimages/images/'.$row['store_image'].'" width="100px" height="100px" >';
echo '</div>';
}
在这里我很容易得到图像。但在这里您可以看到我使用了 width="100px"
和 height="100px"
作为图像大小。这扰乱了图像的纵横比。为了解决这个问题,我在谷歌上进行了搜索,我得到了 imagemagick是一个不错的选择。但是我不知道如何将 imagemagick 与简单的 php 一起使用(我没有使用任何类、方法)以及如何在这里使用 imagemagick?任何帮助和建议都将非常感激。谢谢
最佳答案
下面是保持图片比例的方法
list($origWidth, $origHeight) = @getimagesize("path/to/image");
$origRatio = $origWidth/$origHeight;
$resultWidth = 100;
$resultHeight = 100;
if ( $resultWidth/$resultHeight > $origRatio ) {
$resultWidth = $resultHeight * $origRatio;
} else {
$resultHeight = $resultWidth / $origRatio;
}
关于php - 在从数据库中获取图像时,使用带有 php 的图像 magick 来调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18978733/