1

我想改变我的图像的颜色,但它保持透明度。我不能使用这种fill()方法,因为它有规则的清晰规则,而且我的图像不规则。那么我应该如何处理干预/图像?

4

1 回答 1

4

我找到了一种在干预中使用 colorize 功能的方法。

$image = Image::make($path);
$color = '#abcdef';

$r = round((hexdec(substr($color, 1, 2)) * 200) / 255) - 100;
$g = round((hexdec(substr($color, 3, 2)) * 200) / 255) - 100;
$b = round((hexdec(substr($color, 5, 2)) * 200) / 255) - 100;

// Apply or remove color from a neutral #7F7F7F color image
$image->colorize($r,$g,$b);

我将十六进制颜色的每个分量转换为 dec,然后将其转换为从 -100 到 100 的比例,以在 colorize 函数中使用它。这必须在完全中性灰色的完全#7F 图像中完成,才能获得正确的颜色。

这是一个非常古老的问题,但我希望这可以帮助其他遇到同样问题的人。

于 2017-07-05T22:16:18.393 回答