简体   繁体   English

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

[英]Python PIL/imagemagick merge gradient over the base image

I already know how to get a gradient image but how can I merge the gradient image and the base image so that it looks something like this: link 我已经知道如何获取渐变图像,但是如何合并渐变图像和基础图像,使其看起来像这样: link

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

or another approach has been suggested here Base image is 在这里建议另一种方法基本图像是 基本图片 The output should the gradient at the bottom like this: https://1drv.ms/i/s!Aoi-6MWkMNN4kGLYNmqN9dm1nrOD 输出应该像下面这样在底部渐变: https : //1drv.ms/i/s!Aoi-6MWkMNN4kGLYNmqN9dm1nrOD

I can only guess what you are trying to do, so my first attempt would be this: 我只能猜测您要做什么,所以我的第一个尝试是:

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

在此处输入图片说明

The important parts are that the gradient goes from black to transparent rather than black to white , else you will get white on your background which I am guessing you don't want. 重要的部分是渐变是从黑色到透明,而不是从黑色到白色 ,否则您的背景会变成白色 ,我猜这是您不想要的。

The -gravity south places the gradient at the bottom and also sets the initial position of the title, but that is then shifted 20 pixels up from the bottom with -annotate +0+20 . -gravity south将渐变放置在底部,并且还设置了标题的初始位置,但是随后使用-annotate +0+20从底部向上移动了20个像素。

Hope that helps. 希望能有所帮助。

Update 1 更新1

If you want to control the gradient, you can alter the start and end of it using rgb() constants, like this: 如果要控制渐变,可以使用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

在此处输入图片说明

Or you can make it go from one colour to another: 或者,您可以使其从一种颜色变为另一种颜色:

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

在此处输入图片说明

Or you can change the blending mode, so here I use colorBurn : 或者您可以更改混合模式,因此在这里我使用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

在此处输入图片说明

If you want to try some other blending modes, you can get a list with: 如果您想尝试其他混合模式,则可以使用以下列表:

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

Update 2 更新2

If you want to blur the text, it is easier to create that first, blur it, and then underlay the background like this: 如果要使文本模糊,则首先创建文本,对其进行模糊处理,然后再像这样对背景进行底衬变得更容易:

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

在此处输入图片说明

Update 3 更新3

If you want to shadow your text, and control your gradient and do a load of other things, you may be better off doing one thing at a time. 如果要阴影化文本,控制渐变并执行其他操作,则一次执行一项操作可能会更好。 So, let's try and make your text with a drop-shadow first, then put a gradient on your image then put the shadowed text on top of that - and hope we are getting close! 因此,让我们先尝试使用阴影创建文本,然后在图像上放置渐变,然后在阴影文本上放置阴影-希望我们越来越近了!

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

在此处输入图片说明

Now put gradient on main image and title top of that: 现在在主图像和标题上方放置渐变:

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM