4

I'm trying to reproduce a blurred/text-shadow effect using reportlab. Something like this.

image

So far my approach was to work with the filling color (the text itself or the background), but I don't think I'm going to be successful if I follow this path because the class only accepts an opacity (alpha) paramater besides the ones that defines the color itself. Now I'm trying to find some font that will mimic this effect.

So, It's possible to reproduce the desirable effect with reportlab? If yes, which approach should I use to achieve it?

Thank you very much!

Dharmang
  • 3,018
  • 35
  • 38
Murilo Sitonio
  • 270
  • 7
  • 30

2 Answers2

4

I don't see any straightforward way to achieve a blurry effect as you can achieve with CSS or even with the PIL library using reportlab.

You can try one of the following fonts that more-less mimic this effect: Acidic, ExtraBlur, Erthqake Font, Static Buzz Font , vtks trunkset Font and use the pdfmetrics.registerFont() and TTFont() methods (e.g. using the Static Buzz Font):

from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfgen.canvas import Canvas

canvas = Canvas('temp.pdf')
pdfmetrics.registerFont(TTFont('StaticBuzz', '/path/to/TTF-file/StaticBuzz.ttf')) #Change the path to the .ttf file.
canvas.setFont('StaticBuzz', 32)
canvas.drawString(0, 700, "Sample usage of StaticBuzz Font.")
canvas.save()
Daniel Ocando
  • 3,554
  • 2
  • 11
  • 19
  • Yep, I'm going thorugh this direction (with a slightly different font from the ones you suggested). Unfortunately isn't the solution I was hoping but it will handle for now :). Thanks for the response! – Murilo Sitonio Jun 09 '20 at 13:49
  • Sadly, it's not possible using merely any attribute from a reportlab class. – Daniel Ocando Jun 09 '20 at 13:53
4

If it is an option (free standing text / headline), you could transform the text to a picture first and then blur it using the PIL library.

The filter can be adapted by setting radius so a strong blur effect can be achieved:

before after

from PIL import ImageFilter
from PIL import Image

img = Image.open('test.png')

blurred_img = img.filter(ImageFilter.GaussianBlur(radius=5))
blurred_img.show()
Nico Müller
  • 1,784
  • 1
  • 17
  • 37