Skip to main content

A simple image cropper for Streamlit, with fixes added

Project description

Streamlit - Cropper

A Forked version of the original streamlit-cropper, with added fixes

Fixes:

  1. should_resize_image=False now works
  2. Using manual box_function in box_algorithm will hence work as well
  3. Remove stroke width from overall crop dimension

Installation

pip install streamlit-cropper-fix

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 Turner Anderson, zoncrd and yanirs for their contributions

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_cropper_fix-0.3.6.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamlit_cropper_fix-0.3.6-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_cropper_fix-0.3.6.tar.gz.

File metadata

  • Download URL: streamlit_cropper_fix-0.3.6.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for streamlit_cropper_fix-0.3.6.tar.gz
Algorithm Hash digest
SHA256 ac7f7a1134c4a1243c2e67278cbb0ee2dad6dfcc5fac05850a0bed85bf06991a
MD5 31f5f0b37c8d7c38e61542aefed254c5
BLAKE2b-256 f6b6a5f1c61f05f2d2ca5a1c92b6d5bf1f29a62802e816deb1263cdfc74095f6

See more details on using hashes here.

File details

Details for the file streamlit_cropper_fix-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_cropper_fix-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 043125cd6ca0f9091fe05a5728c8acc2614e2262d4cae43d78d76d81449bff8d
MD5 4b93a373623a50b149cb6df2764a4885
BLAKE2b-256 dccf33f272c58b9410bc182bb13bdf3370355c1d40518072d0dd3aa3ff57c9bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page