Streamlit - Cropper
A streamlit custom component for easy image cropping
Installation
pip install streamlit-cropper
Example Usage
import streamlit as st
from streamlit_cropper import st_cropper
from PIL import Image
st.set_option('deprecation.showfileUploaderEncoding', False)
# Upload an image and set some options for demo purposes
st.header("Cropper Demo")
img_file = st.sidebar.file_uploader(label='Upload a file', type=['png', 'jpg'])
realtime_update = st.sidebar.checkbox(label="Update in Real Time", value=True)
box_color = st.sidebar.color_picker(label="Box Color", value='#0000FF')
aspect_choice = st.sidebar.radio(label="Aspect Ratio", options=["1:1", "16:9", "4:3", "2:3", "Free"])
aspect_dict = {
"1:1": (1, 1),
"16:9": (16, 9),
"4:3": (4, 3),
"2:3": (2, 3),
"Free": None
}
aspect_ratio = aspect_dict[aspect_choice]
if img_file:
img = Image.open(img_file)
if not realtime_update:
st.write("Double click to save crop")
# Get a cropped image from the frontend
cropped_img = st_cropper(img, realtime_update=realtime_update, box_color=box_color,
aspect_ratio=aspect_ratio)
# Manipulate cropped image at will
st.write("Preview")
_ = cropped_img.thumbnail((150,150))
st.image(cropped_img)
References
Acknowledgments
Big thanks to zoncrd and yanirs for their contributions
Metadata
Release files for streamlit-cropper 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| streamlit_cropper-0.3.1.tar.gz | 803.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| streamlit_cropper-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.6 MB
Release files / streamlit_cropper-0.3.1.tar.gz
| Download URL | streamlit_cropper-0.3.1.tar.gz |
|---|---|
| Size | 803.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7d22befae2dd861ea9ac8ca65e1fa6c27af25e9350b365ee2d3d043d81ff76fe
|
|
BLAKE2b-256 checksum How to use checksums |
0f74d1729570d91b09b83fb05ed94ee7ff88e3e756ad27836639b69a12817875
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|
Release files / streamlit_cropper-0.3.1-py3-none-any.whl
| Download URL | streamlit_cropper-0.3.1-py3-none-any.whl |
|---|---|
| Size | 810.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26630e5366c9f0f8ed391d8bd7ab8386acf42cd9f30dd6e708b9b32beeef57e1
|
|
BLAKE2b-256 checksum How to use checksums |
44db955b8d957acde8b61f7669f2f1ae4cab4e9bad44211a186a7c6558d45656
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.1
|