gpt4 book ai didi

ruby - 使用 imagemagick 更改图像的颜色

转载 作者:数据小太阳 更新时间:2023-10-29 06:36:08 27 4
gpt4 key购买 nike

我想使用 rmagick/imagemagick 更改图像的前景色。更具体地说:我想转换 blackwhite glyphicons-halflings图标(包含在 twitter bootstrap 中)转换为深蓝色 glyphicons-halflings 图标。 (如果我能指定 hexcolor 或 RGB 颜色就好了。)

我不知道这是否可行,但我点击了 imagemagick 文档,发现的唯一内容是 convert --size 100x100 xc:skyblue glyphicons-halflings.png -composite foo.png,问题在于这仅在您指定大小时有效,并且它正在更改前景色而不是背景色。而且是天蓝不是深蓝。

所以有人知道我如何将白色或黑色的 glyphicons-halflings 图标转换为蓝色 glyphicons-halflings 图标吗? (rmagick/ruby 代码片段的奖励点)

最佳答案

快速回答:

convert glyphicons-halflings.png -alpha extract -background blue \
-alpha shape blue-glyphicons-halflings.png

blue-glyphicons-halflings.png

注意:除了 blue,您可以使用任何命名的颜色,或 RGB 或 RGBA 等(参见 http://www.imagemagick.org/script/command-line-options.php#fill)。

解释:

我们分两步为图标“着色”:

  • 从图标中提取 alpha channel ; (注意:原始图标的颜色无关紧要,我们正在提取它的 alpha channel )
  • 将上述蒙版应用到您选择的彩色背景上;

有关更多信息,请阅读以下文档:

PS:上面的解决方案在实现jQuery ThemeRoller rewrite时研究过https://github.com/jquery/download.jqueryui.com/issues/77

关于ruby - 使用 imagemagick 更改图像的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12165304/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com