Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from Quartz import NSPasteboard, NSPasteboardTypeTIFF
- from Cocoa import NSImage, NSBitmapImageRep
- import io
- def send_to_clipboard(image):
- # Convert the Pillow image object to TIFF format
- output = io.BytesIO()
- image.save(output, format="TIFF")
- tiff_data = output.getvalue()
- output.close()
- # Create an NSImage from the TIFF data
- ns_image = NSImage.alloc().initWithData_(tiff_data)
- # Create a bitmap representation
- image_rep = NSBitmapImageRep.alloc().initWithData_(tiff_data)
- # Set the image to the clipboard
- pasteboard = NSPasteboard.generalPasteboard()
- pasteboard.declareTypes_owner_([NSPasteboardTypeTIFF], None)
- pasteboard.setData_forType_(image_rep.TIFFRepresentation(), NSPasteboardTypeTIFF)
- # 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