Here's my code:
import cairo import os from PIL import Image imagesize = (512,128) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, *imagesize) cr = cairo.Context(surface) cr.select_font_face("Verdana", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL) cr.set_font_size(24) cr.set_source_rgb(1, 1, 1) ... surface.write_to_png("MyImage.png")
As you can see I'm drawing some white text to this PNG, but the background defaults to an opaque black. How do I make the png transparent so that only the white text is showing?
I was able to setup a transparent background using set_source_rgba() and using 0.0 for the alpha value:
I then also had to make sure to write the text with something like this:
Here's the full code that works for me: