Forum Archive

How to save ui.image

sara55

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

omz

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))
sara55

Thank you very much, I will try.

sara55

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

omz

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

sara55

Thank you very much