0

I have a GdkPixbuf data structure loaded from a svg file (Environment - Python3.7; Linux). Depending upon the area of different object id in svg, I want to mask/unmask the GdkPixBuf Image.

I have searched the python binding for Gtk, Gdk and GdkPixbuf without any luck. Any suggestion is welcome.

Example Code:

from gi.repository import GdkPixbuf

figure_file = 'QWERTY.svg'
width, height = 600, -1
preserve_aspect_ratio = True
im_data = GdkPixbuf.Pixbuf.new_from_file_at_scale(figure_file, width, height, preserve_aspect_ratio)

# Now I want to mask all parts im_data except 20x10 pixel rectangle at pixel(100,120)
maksed_im_data = mask_pixbuf(im_data, 100, 120, 20, 10)

mask_pixbuf function should return masked PixBuf (of the original size) where only the rectangular region of size 20 x 10 centered at (100,120) is visible. Other parts of the returned pixbuf is expected to be transparent.

MS_
  • 741
  • 1
  • 6
  • 10
  • Is your question how to write a `mask_pixbuf` function which does what you need? Did you try anything? It seems more an image manipulation question, not really related to gtk or gdk. – Valentino Feb 10 '19 at 16:54
  • @Valentino I searched the documentation. It seems that there is function for extracting mask from PiXBuf (gdk_pixbuf_render_pixmap_and_mask; without Python binding though) but there is no function for my use case i.e. to put mask. Further, I do not want to use disk. I prefer masking/unmasking with in-memory PixBuf because there are many ids in svg file and saving one PNG for each case will be pretty slow. – MS_ Feb 10 '19 at 17:00

0 Answers0