gd - PHP < 5.5 的 imagecrop() 替代方案

标签 gd php-5.4 php-5.5

一个出于好奇心的简单问题,可能有一个复杂的答案:是否可以通过结合其他 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/

相关文章:

php - 启用/安装 GD 扩展? --without-gd

php - PHP xmlwriter 文档中的换行符

PHP 5.4 多部分/表单数据 UTF-8 编码

家庭网络上的 PHP 5.4 内置 Web 服务器

memcached - 用于 WAMP 2.5 的 php_memcache.dll - PHP : 5. 5.12 - Window8:64 位 - VC11

PHP GD ttftext 居中对齐

php - 将 C 转换为 PHP

php - 使用 PHP imageCreateFromJpeg 复制图像并保留其 EXIF/IPTC 数据?

php - 在 PHP 5.5.9 的 PHP 开关中使用常量

mysql_real_escape_string() 和 mysql_get_server_info() : Access denied for user '' @'127.0.0.1' (using password: NO)