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.


    Passing An Image Back To Workflow

    Pythonista
    7
    25
    22003
    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.
    • MartinPacker
      MartinPacker last edited by

      Something for y'all to pick the bits out of...

      A reply from @WorkflowHQ on Twitter contained the following...

      "Also regarding sending images, Workflow can decode base64 encoded images."

      Does this help us here? Can we encode images base64?

      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        @MartinPacker Encoding images as base64 should be fairly straightforward in Python. Do you have any more details?

        1 Reply Last reply Reply Quote 0
        • ccc
          ccc last edited by

          https://forum.omz-software.com/topic/2974/need-python-script-to-decode-or-encode-in-base64

          1 Reply Last reply Reply Quote 0
          • omz
            omz last edited by

            I figured out how to do it without using the clipboard. The trick is basically to use "Get Contents of URL" with a data: URI that gets passed to the workflow via the workflow:// scheme, containing base64-encoded image data.

            Here's the script:

            import webbrowser
            import base64
            from PIL import Image
            import io
            from urllib.parse import quote
            
            img = Image.open('test:Lenna')
            
            buffer = io.BytesIO()
            img.save(buffer, 'PNG')
            data_uri = 'data:image/png;base64,' + base64.b64encode(buffer.getvalue()).decode('ascii')
            
            webbrowser.open('workflow://run-workflow?name=EditBase64Image&input=' + quote(data_uri, ''))
            

            ...and the workflow should be something like this:

            Screenshot

            1 Reply Last reply Reply Quote 0
            • shtek
              shtek last edited by

              invalid base64 encode.
              remove 'data:image/png;base64,' like this:

              data_uri  = base64.b64encode(buffer.getvalue()).decode('ascii')
              

              now it works
              sd

              s

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