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.


    How to save ui.image

    Pythonista
    ui.image
    2
    6
    4643
    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.
    • sara55
      sara55 last edited by

      I am new to python and Pythonista.
      I would like to save ui.image and not create it very time from JPEG.
      Is it possible?

      Thanks

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

        Yes, that's possible, here's an example:

        import ui
        
        img = ui.Image('test:Lenna') # Just load a sample image here...
        
        # Save as PNG:
        with open('test.png', 'wb') as f:
            f.write(img.to_png())
        
        # Save as JPEG:
        with open('test.jpg', 'wb') as f:
            quality = 0.9 # From 0.0 (more compression) to 1.0 (better quality)
            f.write(img.to_jpeg(quality))
        
        1 Reply Last reply Reply Quote 0
        • sara55
          sara55 last edited by

          Thank you very much, I will try.

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

            Thanks, it worked.
            How would I load a JPG image ?
            Img = ?

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

              img = ui.Image('test.jpg')

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

                Thank you very much

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