'how do I resize the image shown by st.image

I have the following code:

bottom_image = st.file_uploader('', type='jpg', key=6)
if bottom_image is not None:
    st.image(bottom_image)

the problem I run into is some of the images are very large and I want to be able to size them to a fixed size.

Not sure if this makes a difference or not, but the file_uploader is in a column.

I looked at creating a thumbnail but I could not figure that out.

Thoughts?



Solution 1:[1]

You can adjust the width parameter.

st.image(bottom_image, width=400)

Or you can use the Pillow lib to manipulate the width and height.

from PIL import Image

bottom_image = st.file_uploader('', type='jpg', key=6)
if bottom_image is not None:
    image = Image.open(bottom_image)
    new_image = image.resize((600, 400))
    st.image(new_image)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ferdy