php - 在从数据库中获取图像时,使用带有 php 的图像 magick 来调整图像大小

标签 php mysql image-processing imagemagick

在 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/

相关文章:

python - 如何加载图像并将其转换为适合 PyTorch 的张量?

MySQL/MariaDB 不区分大小写的排序规则仍然区分大小写吗?

javascript - 如何在单击复选框时使用数据库中的值填充输入文本字段

php - 检查 PHP 指定的开始时间和结束时间之间的可用时间

php - 将 php 数组转换为单个 JSON 对象

php - 在单个查询中使用两个推测表?

php - mysql 创建动态表

Android Camera参数setPictureSize导致图片出现条纹

java - 使用 Scale 调整大小时,具有透明背景的 PNG 变为黑色

php - PHP include_path 主值从何而来?