Forum Archive

Can I resize ui.image pictures in Pythonista?

halloleooo

I know I can do resizing with pillow(i.e. reducing the dimensions of the picture), but to start with I have the picture as a ui.image object. So can I resize it as that (before I send it over to pillow)?

cvp

@halloleooo try

import ui

ui_image = ui.Image.named('test:Lenna')
w,h = ui_image.size
ui_image.show()
print(w,h)
wi = 100
hi = wi*h/w
with ui.ImageContext(wi,hi) as ctx:
    ui_image.draw(0,0,wi,hi)
    ui_resize = ctx.get_image()
print(ui_resize.size)
ui_resize.show()    
halloleooo

Thanks @cvp! This is fantastic - exactly what I need!

cvp

@halloleooo did you see my little script in your other topic "How to debug crash of image script when it's called as extension"

halloleooo

@cvp Yes I did. Thx.