是否有任何 PHP/GD 函数可以计算这个:
Input: image width, image height and an aspect ratio to honor. Output: the width/height of the max centered crop that respects the given aspect ratio (despite image original aspect ratio).
示例:图像为 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 。
关于php - 给定图像和纵横比的最大裁剪区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8541380/