gpt4 book ai didi

php - 想像 |渐变贴图

转载 作者:行者123 更新时间:2023-12-05 08:33:47 34 4
gpt4 key购买 nike

我正在尝试使用 imagick 在图像上获得这种效果。在 photoshop 中它被称为渐变贴图,但我在 imagick 中找不到类似的东西。

我想我需要先把它变成黑白的,但我不知道这样做之后如何添加颜色。

希望对您有所帮助!谢谢

--- 编辑:---

  • 我使用的是 Imagick,而不是 imagemagick。
  • 请注意图片中有两种颜色,它不仅仅是彩色的。深蓝色代表较深的颜色,浅绿色/浅绿色代表较浅的颜色。

enter image description here

最佳答案

PHP Imagick 版本

现在明白了你的需求,我做了一个Imagick PHP版:

<?php
// Load input image
$image = new Imagick('landscape.jpg');

// Desaturate image
$image->modulateImage(100,0,100);

// Make duotone CLUT
$clut = new Imagick();
$clut->newPseudoImage(255,1,"gradient:darkblue-aqua");

// Apply duotone CLUT to image
$image->clutImage($clut);

// Output result
$image->writeImage('result.jpg');
?>

enter image description here

更新的答案

哦,我想你想要一个“双色调”而不是一个“色调”。基本上,您需要将图像去饱和为单色,制作双色调 CLUT(颜色查找表)并应用它。

这是制作 CLUT 的方法:

convert -size 1x256! gradient:navy-orange duotone-clut.png

enter image description here

这显然会使你的深色调变成海军蓝,而你的高光变成橙色,但你可以随心所欲地使用这些颜色。您还可以根据需要指定任何 RGB(或 HSL)阴影,语法如下:

convert -size 1x256! gradient:"rgb(255,255,0)-rgb(23,45,100)" ...

以下是将图像去饱和化为灰色然后应用 CLUT 的方法:

convert landscape.jpg -modulate 100,0 \
-size 256x1! gradient:navy-orange -clut result.jpg

-modulate 有 3 个参数 - 色调、饱和度和亮度。通过指定 100,0,我将 Hue 保持在原来的 100%,并将 Saturation 降低为零,并保持 Lightness 不变。

enter image description here

顺便说一下,如果你想要一个有 3 种颜色的“tritone”,一种用于阴影,一种用于中间调,一种用于高光,你可以这样制作:

convert -size 1x1! xc:yellow xc:magenta xc:cyan +append -resize 256x1! -scale x20 clut.png

enter image description here

这给出了这个:

enter image description here

您还可以在 CLUT 中四处移动交叉点,方法是使用对比度拉伸(stretch)或让更大比例的 CLUT 填充相同的颜色。在这里,我通过使用 2 个黄色 block 使阴影颜色“更长”

convert -size 1x1! xc:yellow xc:yellow xc:magenta xc:cyan +append -resize 256x1!  clut.png

enter image description here

这会产生“更长”的阴影:

enter image description here

显然你也可以制作四色调(quad-tone)。

原始答案

有多种方法可以实现这种效果。因此,从这张图片开始:

enter image description here

您可以像这样使用tint,它对应于PHP 中的tintImage(),描述here :

convert landscape.jpg -colorspace gray -fill "rgb(10,100,130)" -tint 100 result.png

enter image description here

或者您可以克隆您的初始图像并用您的色调填充克隆,然后将其合成在图像的顶部。您将在 PHP 中使用 colorizeImage(),如 here 所述:

convert landscape.jpg -colorspace gray                  \
\( +clone -fill "rgb(10,100,130)" -colorize 100% \) \
-compose overlay -composite result.png

enter image description here

关于php - 想像 |渐变贴图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36823310/

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