omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    2
    3
    56
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Austin Ares
      Austin Ares last edited by

      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.

      omz 1 Reply Last reply Reply Quote 0
      • omz
        omz @Austin Ares last edited by omz

        @Austin-Ares You'd have to save your image to a temporary file to useconsole.quicklook(). Here's an example of a function that takes a PIL or ui 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'))
        
        Austin Ares 1 Reply Last reply Reply Quote 2
        • Austin Ares
          Austin Ares @omz last edited by

          @omz Okay thank you anyways. It feels kind of "janky" but that's how it's going to have to work 😂

          Good day,

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors