Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gi
- gi.require_version("Gtk", "3.0")
- from gi.repository import Gtk, Gdk, GdkPixbuf
- from PIL import Image
- def send_to_clipboard(image):
- # Create a buffer in memory to hold the image data
- buffer = io.BytesIO()
- image.save(buffer, format="PNG")
- loaded_image = GdkPixbuf.PixbufLoader.new_with_type('png')
- loaded_image.write(buffer.getvalue())
- pixbuf = loaded_image.get_pixbuf()
- loaded_image.close()
- # Get the clipboard
- clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
- # Set the clipboard image
- clipboard.set_image(pixbuf)
- clipboard.store()
- # Open an image using Pillow
- image_path = 'example.png'
- image = Image.open(image_path)
- # Send the image to clipboard
- send_to_clipboard(image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement