Seeking Help with Displaying High-Quality PIL Images in Streamlit

Hello Streamlit community,

I hope this message finds you well. I’m currently working on a Streamlit project, generating images using the PIL (Python Imaging Library) library. My goal is to display these images with the highest possible quality from the original source (2400x1600) while controlling their size on the page.

def combine_images(background, overlay, position=(0, 0), inverse_color=False, isPath=True, size = (256,256)):
        # Resize overlay image if needed
    overlay = overlay.resize(size)

    # Invert colors if specified
    if inverse_color:
        overlay = ImageOps.invert(overlay.convert("RGB"))

    # Paste the overlay image onto the background
    background.paste(overlay, position, overlay)

    return background
def display_png(img):
    st.image(img, use_column_width=True, output_format='PNG')

If anyone has experience or insights into optimizing image quality and size control in a Streamlit app with images generated using PIL, I would greatly appreciate your assistance. Feel free to check out my current project on website for context.

Thank you in advance for your help!

Best regards

I don’t see how using PIL to generate the mages is relevant. It is unclear which kind of control you want to have over the size. In the example you are just delegating to streamlit, which looks like the right thing to do if you want the image to adjust to the available space. But then you don’t need to do anything else, streamlit will take care of the resampling.