Skip to main content

A simple image cropper for Streamlit

Project description

Streamlit - Cropper

A streamlit custom component for easy image cropping

Installation

pip install streamlit-cropper-ext

Example Usage

import streamlit as st
from streamlit_cropper_ext import st_cropper_ext
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_ext(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

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-ext-0.2.1.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

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

streamlit_cropper_ext-0.2.1-py3-none-any.whl (1.0 MB view details)

Uploaded Python 3

File details

Details for the file streamlit-cropper-ext-0.2.1.tar.gz.

File metadata

  • Download URL: streamlit-cropper-ext-0.2.1.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for streamlit-cropper-ext-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d24410b59eebc552abccc397422be8f95b3f6ad2e403f4820ec9b8ae95100596
MD5 4a70bc5749040de53bab78b78a03560c
BLAKE2b-256 24c710f521c9c06dd57c6209df71cbe9a8e457e091c4318ef742e3ea1010b63f

See more details on using hashes here.

File details

Details for the file streamlit_cropper_ext-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_cropper_ext-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 174440add6d90384c047e017c8ccfad6edc65e2c1fe015070d776549dbe4abb9
MD5 624da2554dc37faceeffb5c7da34cc69
BLAKE2b-256 35d8b6e41d34d30ed301315efe318a8e6a3097a8f6ea00e0e8684a1686922ecb

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