我目前正在尝试使用PHP获取图像的宽高比.例如,使用这些值:
$thumb_width = 912;
$thumb_height = 608;
Run Code Online (Sandbox Code Playgroud)
我可以得到纵横比(16:9,3:2,2:3等).所以在这种情况下:
$ratio = '3:2';
Run Code Online (Sandbox Code Playgroud)
问题是:我不知道它的新宽度或高度.所以我不能做那样的事情:(original height / original width) x new width = new height
有任何想法吗 ?
注意:我不想调整图像大小,只需计算其宽高比和宽高比.
所以你需要获得图像的大小
http://php.net/manual/en/function.getimagesize.php
list($width, $height, $type, $attr) = getimagesize("path/to/your/image.jpg");
Run Code Online (Sandbox Code Playgroud)
所以在这里你必须$width和$height准备
然后你可以在这里使用这个答案/sf/answers/640045731/将结果转换$width/$height为比率.
| 归档时间: |
|
| 查看次数: |
8068 次 |
| 最近记录: |