How to convert an UI image to a Pillow image
-
I am still experimenting with Pillow and UI images...
Now I try to convert a small UI image into a Pillow image, but somehow this doesn't work. First I tried:
ui_image = appex.get_images(image_type='ui') pil_image = ui_image.to_png() print(pil_image.size)
This gives my an error because
ui_image.to_png()
doesn't seem to create a Image (but only the data).Then I thought about
... s = ui_image.size pil_image = Image.frombuffer(mode, size, ui_image.to_png())
but here I have no idea what to use for
mode
...Any idea how to convert an UI image to a Pillow image?
-
import io . . . def ui2pil(ui_img): return Image.open(io.BytesIO(ui_img.to_png()))
-
@cvp This is amazing! Where do you know all these tricks from? π
-
@halloleooo said:
Where do you know all these tricks from?
I'm sure this comes from the forum, full of amazing guys. This forum does not offer an easy way to search but if you use Google with "Pythonista forum pil ui.image" you should find it.
Of course, I have a lot of scripts thus I search among mines first.
Γdit: I'm sure that if you use a lot Pythonista, you'll become one of these amazing guys π