一个出于好奇心的简单问题,可能有一个复杂的答案:是否可以通过结合其他 GD 函数来模拟早期版本(例如 5.4)中的新 PHP 5.5 imagecrop()?
Awn..但是没有 imagecrop() black line bug , 请。 :p
最佳答案
这应该是 imagecrop()
的直接替代品(没有错误...):
function mycrop($src, array $rect)
{
$dest = imagecreatetruecolor($rect['width'], $rect['height']);
imagecopy(
$dest,
$src,
0,
0,
$rect['x'],
$rect['y'],
$rect['width'],
$rect['height']
);
return $dest;
}
用法:
$img = mycrop($img, ['x' => 10, 'y' => 10, 'width' => 100, 'height' => 100]);
请注意,该错误显然已在 PHP 5.6.12 中修复。 .
关于gd - PHP < 5.5 的 imagecrop() 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26722811/