-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexample.py
85 lines (67 loc) · 1.86 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import annotations
import streamlit as st
import streamlit_image_crop
from streamlit_image_crop import image_crop
from streamlit_image_crop import Crop
streamlit_image_crop._DEBUG = True
def main() -> None:
st.title("React Image Crop")
st.sidebar.header("Parameters")
fixed_aspect_ratio = st.sidebar.checkbox("Fixed aspect cropping", value=False)
if fixed_aspect_ratio:
aspect_ratio = st.sidebar.slider(
"Aspect ratio",
value=1.0,
min_value=0.2,
max_value=5.0,
step=0.2,
)
else:
aspect_ratio = None
min_width = st.sidebar.slider(
"Minimum width",
value=0,
min_value=0,
max_value=200,
)
min_height = st.sidebar.slider(
"Minimum height",
value=0,
min_value=0,
max_value=200,
)
max_width = st.sidebar.slider(
"Maximum width",
value=1000,
min_value=0,
max_value=1000,
)
max_height = st.sidebar.slider(
"Maximum height",
value=1000,
min_value=0,
max_value=1000,
)
rule_of_thirds = st.sidebar.checkbox("Rule of Thirds", value=False)
circular_crop = st.sidebar.checkbox("Circular Crop", value=False)
f = st.file_uploader("Choose a image")
if f is None:
return
bytes_image = f.getvalue()
col_left, col_right = st.beta_columns(2)
with col_left:
image_cropped = image_crop(
bytes_image,
crop=Crop(aspect=aspect_ratio),
min_width=min_width,
min_height=min_height,
max_width=max_width,
max_height=max_height,
rule_of_thirds=rule_of_thirds,
circular_crop=circular_crop,
)
if image_cropped is None:
return
with col_right:
st.image(image_cropped)
main()