0

嘿,我想弄清楚如何调整高度大于宽度的图像的大小。需要显示图像的区域的正常宽度和高度为:

width  = 1000px
height = 700px

我需要什么类型的数学才能将其调整到适当的宽度/高度而不用拧紧它?

测试图像大小为:

 width  = 1451
 height = 2200

我正在考虑这样做:

(700/org.height)

但这并没有得出正确的数字462

在 Photoshop 中,将高度更改为700会产生宽度值462

4

2 回答 2

1

所以你想缩放你的图像,使它尽可能大地适应 1000x700 的正方形而不拉伸它?你可以这样做:

$availH = 700;
$availW = 1000;
$imageH = 2200;
$imageW = 1451;

// you know you want to limit the height to 700
$newH = $availH;

// figure out what the ratio was that you adjusted (will equal aprox 0.3181)
$ratio = $availH / $imageH;

// now that you have the $ratio you can apply that to the width (will equal 462)
$newW = round(imageW * $ratio);

现在你有了 $newW 和 $newH ,它们是正确缩放图像的新尺寸。你当然可以把它浓缩下来,但我已经把它写出来了,所以每一步都更清楚。

于 2012-12-14T02:15:26.337 回答
0

调整大小时保持纵横比的公式是

original height / original width x new width = new height

资料来源:http ://andrew.hedges.name/experiments/aspect_ratio/

但是您想将其切换为我认为的以下内容:

original width / original height x new height = new width
于 2012-12-14T02:03:08.893 回答