Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Providing QuickLook with an Image from ui.Image
-
Is it at all possible to provide console.quicklook() with not a file path, but a ui.Image or PIL.Image object? I am not knowledgeable enough with ObjC to do this myself.
-
@Austin-Ares You'd have to save your image to a temporary file to use
console.quicklook()
. Here's an example of a function that takes aPIL
orui
image, saves it to a temporary file, shows the quicklook preview, and then deletes the file (no ObjC needed):import console import ui from PIL import Image import os def quicklook_img(img): tempfilename = '.ql_image.png' if isinstance(img, ui.Image): with open(tempfilename, 'wb') as f: f.write(img.to_png()) elif isinstance(img, Image.Image): img.save(tempfilename) else: raise TypeError('Expected an image') console.quicklook(tempfilename) os.remove(tempfilename) #Demo: quicklook_img(Image.open('test:Peppers'))
-
@omz Okay thank you anyways. It feels kind of "janky" but that's how it's going to have to work 😂
Good day,