I'm using Xubuntu 14.04 (an X11/Linux distribution). I've written a Python program using the Pillow (Python Imaging Library) and Tkinter libraries to render user-entered text into an image using a custom bitmap font. I want to quickly bring this image into the running GIMP process as a new layer. Currently it operates by saving the image to a PNG file and then requiring the user to go dig for the PNG file using GIMP's file picker. I thought it would be more convenient if I could save the image to the X11 clipboard so that I could paste it into GIMP.
But all the examples for interacting with the clipboard in Tkinter that I could find through Google are for text, not images. I found how to copy an image in Windows (1, 2): save a BMP file to a BytesIO
, chop off the first 14 bytes, and send the rest to the Windows clipboard as a CF_DIB
. But I don't want to require Wine. There also exists an answer about how to do it in GTK+; is it worth porting the application from Tkinter to PyGTK (for GTK+ 2) or PyGObject (for GTK+ 3), despite the installation headache that it may cause for Windows users? Or is there an easier way than the X11 clipboard to get a PIL.Image.Image
instance into GIMP?