| 1234567891011121314151617181920212223242526272829 |
- from io import BytesIO
- import base64
- import streamlit as st
- def show_image_with_scroll(
- image,
- caption="",
- viewport_width=800,
- viewport_height=1200,
- zoom=1.0
- ):
- buf = BytesIO()
- image.save(buf, format="PNG")
- img_base64 = base64.b64encode(buf.getvalue()).decode("utf-8")
- width = image.width
- height = image.height
- html = f"""
- <div style="border:1px solid #e0e0e0;border-radius:6px;width:{viewport_width}px;height:{viewport_height}px;
- overflow:auto;background:#fff;margin-bottom:0.5rem;">
- <div style="transform:scale({zoom});transform-origin:top left;width:{width}px;height:{height}px;">
- <img src="data:image/png;base64,{img_base64}" style="width:{width}px;max-width:none;display:block;" />
- </div>
- </div>
- """
- st.markdown(html, unsafe_allow_html=True)
- if caption:
- st.caption(caption)
|