python - How to render text on a GdkPixbuf.Pixbuf -


I am trying to add text to a pixbuf, using Python and Gdk3.

For hours, searching the web for information about this topic, and it seems that I have to make a Cairo reference from Pixbuf. Unfortunately, I have zero experience with Cairo, but I I can put this piece of code together: gi.repository import from Gdk def put_text (pixbuf, text, x, y)

 : # GDK window window_rat = GdK. Windows (str) window_trat.width = pixbuff.tv_width () window_tat Het = pixbug.get_height () window_tat.windowprop = gdk Windows type OFFRN # ~ Window_Tread.Window_type = GdK Windows type. TEMP window_attr.redirect = true # ~ window_attr.redirect = false window = Gdk.Window (none, window_attr, Gdk.WindowAttributesType (0)) A reference to window reference = Gdk.cairo_create (window) #make Gdk .cairo_set_source_pixbuf (references, of course, 0, 0) #render text context.move_to (x, y) context.set_font_size (15) context.show_text (text) resulting in the result surface = context.get_target () result = Gdk.pixbuf_get_from_surface (#get surface, 0, 0, surface. Gate_width (), surface.get_hete ()) # ~ window.destroy () return result  

at least to crash my program Not the reason Is it However, this product is entirely pixel transparent. Can someone tell me what I am doing wrong or if there is a better way of doing this?

I finally managed to create a working code, gi.repository import cairo Using to was a big mistake.

  import imported GDK import DEFT def_text (pixifuf, text, x, y): surface = cairo.imageSurface (cairo.FORMAT_ARGB32, pixbuf.get_width (), pixbuf.get_height ( ) Reference = cairo.Context (surface) Gdk.cairo_set_source_pixbuf (references, of course, 0, 0) reference.paint () #paint must be the text fontsize = 20 context.move_to (x, y + fontsize) context.font_size (fontsize) Context.set_source_rgba (0,0,0,1) context.show_text (text) The resulting surface #get #Add = reference .get_target () pixbuf = Gdk.pixbuf_get_from_surface (surface, 0, 0, surface. Gate_width () , Surface.Gate_Height ()) returns pixbuff  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -