Python PIL/imagemagick 在基础图像上合并渐变

Python PIL/imagemagick merge gradient over the base image

我已经知道如何获取渐变图像,但如何合并渐变图像和基础图像,使其看起来像这样: link

convert -size 1327x1327 xc:transparent gradient: grad_image.png

或建议了另一种方法 基本图像是 输出应该像这样在底部渐变:https://1drv.ms/i/s!Aoi-6MWkMNN4kGLYNmqN9dm1nrOD

我只能猜测你想做什么,所以我的第一次尝试是这样的:

convert jelly.jpg \( -size 1140x100! gradient:none-black \) -gravity south -composite -pointsize 36 -fill white -annotate +0+20 "Title Treatment" result.png

重要的部分是渐变从黑色到透明而不是从黑色到白色,否则你的颜色会变白我猜你不想要的背景。

-gravity south 将渐变置于底部并设置标题的初始位置,但随后使用 -annotate +0+20.

从底部向上移动 20 像素

希望对您有所帮助。

更新 1

如果你想控制渐变,你可以使用 rgb() 常量改变它的开始和结束,像这样:

convert jelly.jpg \( -size 1140x100! gradient:"rgba(0,0,0,0.25)"-"rgb(50,50,50)" \) -gravity south -composite -pointsize 36 -fill white -annotate +0+20 "Title Treatment" result.png

或者你可以让它从一种颜色变成另一种颜色:

convert jelly.jpg \( -size 1140x100! gradient:"rgba(0,0,0,0.25)"-"rgba(255,255,0,0.75)" \) -gravity south -composite -pointsize 36 -fill white -annotate +0+20 "Title Treatment" result.png

或者你可以改变混合模式,所以这里我使用colorBurn:

convert jelly.jpg \( -size 1140x100! gradient:"rgba(0,0,0,0.25)"-"rgba(255,255,0,0.75)" \) -gravity south -compose colorburn -composite -pointsize 36 -fill white -annotate +0+20 "Title Treatment" result.png

如果你想尝试一些其他的混合模式,你可以得到一个列表:

identify -list compose:

Atop
Blend
Blur
Bumpmap
ChangeMask
Clear
ColorBurn
ColorDodge
Colorize
CopyAlpha
CopyBlack
CopyBlue
CopyCyan
CopyGreen
Copy
CopyMagenta
CopyRed
CopyYellow
Darken
DarkenIntensity
DivideDst
DivideSrc
Dst
Difference
Displace
Dissolve
Distort
DstAtop
DstIn
DstOut
DstOver
Exclusion
HardLight
HardMix
Hue
In
Intensity
Lighten
LightenIntensity
LinearBurn
LinearDodge
LinearLight
Luminize
Mathematics
MinusDst
MinusSrc
Modulate
ModulusAdd
ModulusSubtract
Multiply
None
Out
Overlay
Over
PegtopLight
PinLight
Plus
Replace
Saturate
Screen
SoftLight
Src
SrcAtop
SrcIn
SrcOut
SrcOver
VividLight
Xor

更新 2

如果你想模糊文本,先创建它,模糊它,然后像这样在背景下加底会更容易:

convert -size 1140x100! gradient:none-black     \
   -pointsize 36 -fill white -gravity south     \
   -annotate +5+25 "Title Treatment" -blur 0x4  \
   -annotate +0+20 "Title Treatment" jelly.jpg +swap -composite result.png

更新 3

如果您想为文本添加阴影、控制渐变并执行大量其他操作,最好一次只做一件事。所以,让我们先尝试用 drop-shadow 制作文本,然后在图像上添加渐变,然后在其上添加阴影文本 - 希望我们越来越接近!

string="Funky Main Title\nSub-title"
convert -size 1200x400 xc:none -pointsize 72 -gravity center   \
       -fill white  -stroke black  -annotate +25+65 "$string"  \
       \( +clone -background black  -shadow 70x4+5+5 \) +swap  \
       -background none -flatten  -trim +repage shadowed.png

现在在主图像和标题顶部添加渐变:

convert jelly.jpg                                                   \
  \( -size 1140x100! gradient:"rgba(0,0,0,0.25)"-"rgb(50,50,50)" \) \
  -gravity south -composite                                         \
  shadowed.png -composite result.png