PHP Imagick API:如何将图像的色调更改为已知的十六进制值

发布于 2024-09-18 08:19:12 字数 488 浏览 1 评论 0原文

我创建模板网站。如果客户选择蓝色、绿色或紫色标题,我不想存储图像的所有这些不同颜色变化。我想以编程方式更改色调。我不想“淹没”它,因为这会删除任何纹理或斜角。

例如,您看到的页面我已经完成了我想要的。 http://sta.oursitesbetter.com/test/index.php

我已经完成这使用 Imagick modulateImage 函数。

然而,我只是抛出随机的“色调”值而不是 RGB 值。我想完成同样的事情,输入 RGB 值。我需要一个类似于 modulateImage 的函数,但它必须采用 RGB 作为值并将图像设置为该色调。

我已经研究了过去5个小时,但不知道该怎么做。我需要帮助。

StackOverflow 的专家是否有 PHP Imagick 解决方案来解决这个颜色难题?

I create template websites. If a client choose a blue or green or purple heading, I don't want to have to store all those different color variations of an image. I want to programmatically change the hue. I do not want to 'flood fill' it because that would remove any textures or bevels.

For example page you see I have accomplished exactly what I want.
http://sta.oursitesbetter.com/test/index.php

I have done this using Imagick modulateImage function.

HOWEVER, I am just throwing random 'Hue' values and not RGB values. I want to accomplish this same thing feeding RGB values. I need a function similar to modulateImage however it must take RGB as value and set the image to that hue.

I have studied for the past 5 hours and cannot figure out how to do it. I need help.

Has any of the gurus of StackOverflow got a PHP Imagick solution to this color quandary?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

和我恋爱吧 2024-09-25 08:19:13

来自 维基百科:Hue #Computing Hue from RGB

\tan h_{Preucil\ hexagon} = \frac{\sqrt{3}\cdot (G - B)}{2\ cdot R - G - B}

$hex=(sqrt(3)*($green-$blue)) /
       (2*($red-$green-$blue));//$red, $green and $blue are each a value in the range 0->255


$img->modulateImage(100, 100, intval($hex*100/256));
//probably 256->100 value above will work, if didn't , try with the following insead.
//$img->modulateImage(100, 100, $hex);

From Wikipedia: Hue #Computing hue from RGB:

\tan h_{Preucil\ hexagon} = \frac{\sqrt{3}\cdot (G - B)}{2\cdot R - G - B}

$hex=(sqrt(3)*($green-$blue)) /
       (2*($red-$green-$blue));//$red, $green and $blue are each a value in the range 0->255


$img->modulateImage(100, 100, intval($hex*100/256));
//probably 256->100 value above will work, if didn't , try with the following insead.
//$img->modulateImage(100, 100, $hex);
穿透光 2024-09-25 08:19:13

另一种选择可能是使用 ImageMagick 以您想要的 RGB 颜色创建单个像素图像,然后查看 ImageMagick 在 HSL 色彩空间中的效果。假设您的 RGB 值为 25,126,200,您可以这样做:

convert -size 1x1! xc:rgb\(25,126,200\) -colorspace HSL txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: (57.0474%,77.7783%,44.1184%)  #920AC71C70F1  hsl(57.0474%,77.7783%,44.1184%)

以下等效方法可能更简洁:

convert xc:rgb\(25,126,200\) -format "%[fx:100*p{0,0}.hue]" info:
57.0476

convert xc:rgb\(25,126,200\) -format "%[fx:100*hue]" info:
57.0476

因此,IM 使其色调为 57.0474%。当然,您不需要运行它并解析文本输出,我这样做只是为了演示这个概念 - 您可以直接在 PHP 中访问像素。

Another option might be to use ImageMagick to create a single pixel image in the RGB colour you want and then see what ImageMagick makes that in HSL colorspace. Say your RGB values are 25,126,200, you could do this:

convert -size 1x1! xc:rgb\(25,126,200\) -colorspace HSL txt:-
# ImageMagick pixel enumeration: 1,1,65535,hsl
0,0: (57.0474%,77.7783%,44.1184%)  #920AC71C70F1  hsl(57.0474%,77.7783%,44.1184%)

The following equivalent methods are maybe a little more succinct:

convert xc:rgb\(25,126,200\) -format "%[fx:100*p{0,0}.hue]" info:
57.0476

convert xc:rgb\(25,126,200\) -format "%[fx:100*hue]" info:
57.0476

So, IM makes that a Hue of 57.0474%. Of course you don't need to run that and parse the text output, I am only doing that to demonstrate the concept - you can access the pixel directly in PHP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文