9

一个由好奇心引发的简单问题,可能有一个复杂的答案:是否可以通过组合其他 GD 函数来模拟早期版本(如 5.4)中新的 PHP 5.5 imagecrop()?

Awn .. 但请不要出现 imagecrop()黑线错误。:p

4

1 回答 1

22

这应该是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中修复。

于 2014-11-04T09:52:25.510 回答