是否有任何PHP / GD函数可以计算:
输入:图像宽度,图像高度和要素的纵横比 . 输出:考虑给定纵横比的最大居中裁剪的宽度/高度(尽管图像原始纵横比) .
示例:图像是1000x500,a.r . 是1.25:最大作物是625x500 . 图像为100x110,最大裁剪为:80x110 .
没有函数计算这个,因为它是基本数学:
$imageWidth = 1000; $imageHeight = 500; $ar = 1.25; if ($ar < 1) { // "tall" crop $cropWidth = min($imageHeight * $ar, $imageWidth); $cropHeight = $cropWidth / $ar; } else { // "wide" or square crop $cropHeight = min($imageWidth / $ar, $imageHeight); $cropWidth = $cropHeight * $ar; }
See it in action .
1 回答
没有函数计算这个,因为它是基本数学:
See it in action .