繁体   English   中英

使用PHP GD库转换图像颜色/色相。 赶上? 它有圆角

[英]Convert an image color/hue using PHP GD library. The Catch? It has rounded corners

我本周正在编写代码以动态更改图像的颜色。 只要图像是正方形或矩形,下面的代码就可以正常工作。 但是,我有一个带有圆角的图像(填充有专色,而拐角外部的背景为白色。)

有人可以告诉我是否有一种简单的方法可以使用imagecolorset函数(或任何其他php方法)为具有圆角的图像着色?

我只希望对图像的非白色区域进行着色(以防万一,我不允许将白色应用于图像)。

请注意,执行此操作的更好方法可能是使用具有透明背景的PNG图像(而不是我的gif图像)。 如果您认为这是更好的方法,请提出建议。

这是我正在使用的功能...

function set_theme_color_header($hex)
{
    $info = hexToRGB($hex); //calls a helper function which translates the hex to RGB
    $img = imagecreatefromgif('header-template.gif'); //again, this could be a PNG image, but we always start with this image, then create a color copy
    $color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
    imagecolorset($img, 0, $info["red"], $info["green"], $info["blue"]);
    imagegif($img, 'header.gif'); //only problem is that the imagecolorset function creates a messy fill at the corners
}

我真的不不是你为什么这样做,但也许看看phpTumb (和它的演示在这里 )。

GD不能很好地处理gif。 我建议创建带有圆角的png图像,然后使用GD的imagefilter($ img,IMG_FILTER_COLORIZE,$ info [“ red”],$ info [“ green”],$ info [“ blue”],$ alpha)函数。 然后将图像另存为gif。

或者,使用php的imagick库从字面上绘制图像。 imagick比GD好十亿倍。 记录不足,但是...基本内容并不难。 请参阅下面的tut链接。

在php.net上搜索“ imagick”以查看所有功能。

imagick教程

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM