streamlit-cropper


Namestreamlit-cropper JSON
Version 0.2.2 PyPI version JSON
download
home_page
SummaryA simple image cropper for Streamlit
upload_time2023-10-05 06:38:45
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Streamlit - Cropper

A streamlit custom component for easy image cropping

![](./demo.gif)

## Installation

```shell script
pip install streamlit-cropper
```

## Example Usage

```python
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

- [streamlit-drawable-canvas](https://github.com/andfanilo/streamlit-drawable-canvas)

## Acknowledgments

Big thanks to zoncrd and yanirs for their contributions

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "streamlit-cropper",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "Turner Anderson <andersontur11@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f5/5c/6f6d183eccfd6b145752d6ac2f2da19f5261916667684744afc9ed2c9a65/streamlit-cropper-0.2.2.tar.gz",
    "platform": null,
    "description": "# Streamlit - Cropper\r\n\r\nA streamlit custom component for easy image cropping\r\n\r\n![](./demo.gif)\r\n\r\n## Installation\r\n\r\n```shell script\r\npip install streamlit-cropper\r\n```\r\n\r\n## Example Usage\r\n\r\n```python\r\nimport streamlit as st\r\nfrom streamlit_cropper import st_cropper\r\nfrom PIL import Image\r\nst.set_option('deprecation.showfileUploaderEncoding', False)\r\n\r\n# Upload an image and set some options for demo purposes\r\nst.header(\"Cropper Demo\")\r\nimg_file = st.sidebar.file_uploader(label='Upload a file', type=['png', 'jpg'])\r\nrealtime_update = st.sidebar.checkbox(label=\"Update in Real Time\", value=True)\r\nbox_color = st.sidebar.color_picker(label=\"Box Color\", value='#0000FF')\r\naspect_choice = st.sidebar.radio(label=\"Aspect Ratio\", options=[\"1:1\", \"16:9\", \"4:3\", \"2:3\", \"Free\"])\r\naspect_dict = {\r\n    \"1:1\": (1, 1),\r\n    \"16:9\": (16, 9),\r\n    \"4:3\": (4, 3),\r\n    \"2:3\": (2, 3),\r\n    \"Free\": None\r\n}\r\naspect_ratio = aspect_dict[aspect_choice]\r\n\r\nif img_file:\r\n    img = Image.open(img_file)\r\n    if not realtime_update:\r\n        st.write(\"Double click to save crop\")\r\n    # Get a cropped image from the frontend\r\n    cropped_img = st_cropper(img, realtime_update=realtime_update, box_color=box_color,\r\n                                aspect_ratio=aspect_ratio)\r\n    \r\n    # Manipulate cropped image at will\r\n    st.write(\"Preview\")\r\n    _ = cropped_img.thumbnail((150,150))\r\n    st.image(cropped_img)\r\n```\r\n\r\n## References\r\n\r\n- [streamlit-drawable-canvas](https://github.com/andfanilo/streamlit-drawable-canvas)\r\n\r\n## Acknowledgments\r\n\r\nBig thanks to zoncrd and yanirs for their contributions\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A simple image cropper for Streamlit",
    "version": "0.2.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/turner-anderson/streamlit-cropper/issues",
        "Homepage": "https://github.com/turner-anderson/streamlit-cropper"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8b509794edb3b1b4a9d2a475c62cf444a0791be60ffeebbcfb76460370fa07a5",
                "md5": "1bc8181c02fbd2b96eed74085dc7428e",
                "sha256": "2affc00abcde7d9061204717f93d5834a18e5ddc54184a60168f58b0e7e97ad0"
            },
            "downloads": -1,
            "filename": "streamlit_cropper-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1bc8181c02fbd2b96eed74085dc7428e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 983959,
            "upload_time": "2023-10-05T06:38:42",
            "upload_time_iso_8601": "2023-10-05T06:38:42.568849Z",
            "url": "https://files.pythonhosted.org/packages/8b/50/9794edb3b1b4a9d2a475c62cf444a0791be60ffeebbcfb76460370fa07a5/streamlit_cropper-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f55c6f6d183eccfd6b145752d6ac2f2da19f5261916667684744afc9ed2c9a65",
                "md5": "8596a7c979737043d88ade1c06564e63",
                "sha256": "40c2852fa5c94d4b4462463ca3d8553a34bcec463300970049d1682680f06019"
            },
            "downloads": -1,
            "filename": "streamlit-cropper-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8596a7c979737043d88ade1c06564e63",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 972290,
            "upload_time": "2023-10-05T06:38:45",
            "upload_time_iso_8601": "2023-10-05T06:38:45.039461Z",
            "url": "https://files.pythonhosted.org/packages/f5/5c/6f6d183eccfd6b145752d6ac2f2da19f5261916667684744afc9ed2c9a65/streamlit-cropper-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-05 06:38:45",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "turner-anderson",
    "github_project": "streamlit-cropper",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "streamlit-cropper"
}
        
Elapsed time: 0.31977s