【问题标题】:resize image while uploading in PHP在 PHP 中上传时调整图像大小
【发布时间】:2014-03-14 21:03:05
【问题描述】:

我有一个文件上传表单,我只上传 jpg、png 和 gif 图像。如果图像的宽度大于 225,我会调整图像的大小,并且高度会自动固定为该宽度。

if($width > 225) {
    $newwidth = 225;
} 
else {
    $newwidth = $width; 
}
$newheight = ($height/$width)*$newwidth;

如果image > 225,上面的代码为我修复了宽度。现在的问题是新的高度是根据图像的宽度。我不希望height 超过150。如何在不拉伸图像的情况下修复它?

【问题讨论】:

标签: php image-uploading resize-image


【解决方案1】:

$newheight大于150的情况下尝试调整宽度,计算比例。在底部添加:

if ($newheight > 150) {
    $proportion = $newwidth/$newheight;
    $newheight = 150;
    $newwidth = 150*$proportion;
}

【讨论】:

    猜你喜欢
    • 2013-09-19
    • 2013-12-07
    • 1970-01-01
    • 2011-01-10
    • 1970-01-01
    • 2012-09-27
    • 2011-04-16
    • 2015-12-05
    相关资源
    最近更新 更多