如何在枕头python中制作文字阴影效果?

how to make text shadow effect in pillow python?

到目前为止我已经达到了this with the pillow, but it's not much visible on some photos, so I want to add some shadow behind the image(called lift effect in texts) like this 这基本上是添加了两个文本,一个是模糊版本,第二个是顶部的普通文本,尺寸稍小(请查看第二张图片以了解) 我找不到关于如何模糊文本的任何地方,如果有人能帮助我,那就太好了

不能 100% 确定您必须从什么开始或您真正想要以什么结束,但这里有一种技术可以在文本后面给您一个柔和的阴影。基本上,您执行以下操作:

  • 为您的文本创建一个足够大的 canvas 的备用部分
  • 在 canvas
  • 上写下您的文字
  • 模糊它以柔化它
  • 将其粘贴到原始图像上
  • 把尖锐的文字写在上面

有一百万种变体,具有不同类型的模糊、不同的字体大小、不同的底色(阴影颜色)以及 pasting/compositing 将模糊文本添加到原始文本上的不同方式。但是,如果您以下面的代码为起点,您可以尝试直到满意为止。

#!/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 = "Whosebug"

# 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')

原图

结果图片