AbH*_*bHi 3 python text image-processing python-imaging-library
到目前为止,我已经用枕头实现了这一点,但在某些照片上不太明显,所以我想在图像后面添加一些阴影(在文本中称为升力效果),就像这样 ,基本上是添加两个文本,一个带有模糊版本,第二个是顶部的普通文本,尺寸稍小(请检查第二张图片以了解)我找不到任何有关如何模糊文本的地方,所以如果有人可以帮助我,那就太好了
不能 100% 确定您必须从什么开始或您真正想要什么结束,但这里有一种技术可以为您在文本后面提供柔和的阴影。基本上,您执行以下操作:
有一百万种变体,包括不同类型的模糊、不同的字体大小、不同的底色(阴影颜色)以及将模糊文本粘贴/合成到原始文本上的不同方式。但如果您以下面的代码为起点,您可以进行试验,直到您满意为止。
#!/usr/bin/env python3
# See also: https://legacy.imagemagick.org/Usage/fonts/#soft_shadow
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageChops
# Open background image and work out centre
bg = Image.open('bg.png').convert('RGB')
x = bg.width//2
y = bg.height//2
# The text we want to add
text = "StackOverflow"
# Create font
font = ImageFont.truetype('/System/Library/Fonts/MarkerFelt.ttc', 60)
# Create piece of canvas to draw text on and blur
blurred = Image.new('RGBA', bg.size)
draw = ImageDraw.Draw(blurred)
draw.text(xy=(x,y), text=text, fill='cyan', font=font, anchor='mm')
blurred = blurred.filter(ImageFilter.BoxBlur(7))
# Paste soft text onto background
bg.paste(blurred,blurred)
# Draw on sharp text
draw = ImageDraw.Draw(bg)
draw.text(xy=(x,y), text=text, fill='navy', font=font, anchor='mm')
bg.save('result.png')
Run Code Online (Sandbox Code Playgroud)
原图
结果图像
归档时间: |
|
查看次数: |
6795 次 |
最近记录: |