Skip to content

Commit

Permalink
Merge pull request #5 from dangkhoasdc/feature/save_as_png
Browse files Browse the repository at this point in the history
save buffer to PNG format instead
  • Loading branch information
blackary authored Jun 13, 2023
2 parents b2d8da3 + 8964d72 commit 98db3ab
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
Binary file added kitty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions pages/png_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import streamlit as st
from PIL import Image

from streamlit_image_coordinates import streamlit_image_coordinates

st.set_page_config(
page_title="Streamlit Image Coordinates",
page_icon="🎯",
layout="wide",
)

"# :dart: Streamlit Image Coordinates"

st.code("pip install streamlit-image-coordinates")

"Try clicking on the image below"

st.write("# PNG with Transparency Example")

with st.echo("below"):
value = streamlit_image_coordinates(
Image.open("kitty.png"),
width=250,
key="png",
)

st.write(value)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="streamlit-image-coordinates",
version="0.1.3",
version="0.1.4",
author="Zachary Blackwood",
author_email="[email protected]",
description=(
Expand Down
2 changes: 1 addition & 1 deletion src/streamlit_image_coordinates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def streamlit_image_coordinates(
src = str(source)
elif hasattr(source, "save"):
buffered = BytesIO()
source.save(buffered, format="JPEG") # type: ignore
source.save(buffered, format="PNG") # type: ignore
src = "data:image/png;base64,"
src += base64.b64encode(buffered.getvalue()).decode("utf-8") # type: ignore
else:
Expand Down
10 changes: 5 additions & 5 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
with col1:
st.write("## Url example")

with st.echo():
with st.echo("below"):
value = streamlit_image_coordinates(
"https://placekitten.com/200/300",
key="url",
Expand All @@ -31,7 +31,7 @@
with col2:
st.write("## Local image example")

with st.echo():
with st.echo("below"):
value = streamlit_image_coordinates(
"kitty.jpeg",
key="local",
Expand All @@ -42,7 +42,7 @@
with col3:
st.write("## Custom size example")

with st.echo():
with st.echo("below"):
value = streamlit_image_coordinates(
"kitty.jpeg",
width=250,
Expand All @@ -52,9 +52,9 @@
st.write(value)

with col4:
st.write("PIL example")
st.write("## PIL example")

with st.echo():
with st.echo("below"):
value = streamlit_image_coordinates(
Image.open("kitty.jpeg"),
key="pil",
Expand Down

0 comments on commit 98db3ab

Please sign in to comment.