[reportlab-users] Semi-transparent gradient

Lele Gaifax lele at metapensiero.it
Mon Apr 4 07:48:08 EDT 2022


Hi all,

I need to put some text on top of an image, and to make sure it's readable I'm
drawing a rectangle filled with a semi-transparent color (say,
rgba(250,250,250,0.6)) and then writing the text over that.

Now I'm asked if it would be possible to use a gradient instead: since the
text is right-aligned, they thinks it would be nicer to have a "progressive
shading" instead of a that equally opaque rectangle under the text.

I tried to use the Canvas.linearGradient() functionality to obtain that,
something like

  path = canvas.beginPath()
  path.rect(113.2*mm, 0, 200*mm, 176.8*mm)
  canvas.clipPath(path, fill=False, stroke=False)
  canvas.linearGradient(113.2*mm, 0, 200*mm, 0,
                        (Color(0, 0, 0, 0.1), Color(0, 0, 0, 0.5)),
                        extend=False)

but, AFAICT, it does not respect the color's alpha, and it basically
completely wipes the underlying image.

Am I missing something, or is there another way to achieve the result I'm
seeking, other than overlying another semi-transparent image over the first?

Thanks in advance for any hint,
ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele at metapensiero.it  |                 -- Fortunato Depero, 1929.



More information about the reportlab-users mailing list