BLUR-51
This commit is contained in:
parent
5e31d09001
commit
4a575c3cb6
@ -10,6 +10,7 @@ color = "rgb(107,99,246)"
|
||||
@template(route="/settings", title="Zdjęcie", image = "/image-icon.png")
|
||||
def settings() -> rx.Component:
|
||||
icon_style = {"width": "20px", "height": "30px", "margin-right": "10px"}
|
||||
|
||||
return rx.vstack(
|
||||
rx.wrap(
|
||||
rx.hstack(
|
||||
@ -19,7 +20,7 @@ def settings() -> rx.Component:
|
||||
background_image="linear-gradient(271.68deg, #7566fe 0.75%, #f96caf 88.52%)",
|
||||
background_clip="text", padding="5px"),
|
||||
rx.text("Dodaj zdjęcie, wybierz obszar i ukryj tożsamość: Anonimizacja zdjęć w mgnieniu oka – szybko, łatwo, bezpłatnie!",
|
||||
font_size="1.2em", text_align="center"), width="50%", margin_left="50px", margin_right = "30px"),
|
||||
font_size="1.2em", text_align="center"), width="50%", margin_left="50px", margin_right="30px"),
|
||||
rx.vstack(
|
||||
rx.upload(
|
||||
rx.vstack(
|
||||
@ -32,14 +33,14 @@ def settings() -> rx.Component:
|
||||
),
|
||||
border=f"1px dotted {color}",
|
||||
padding="1em",
|
||||
width="100%",
|
||||
width="120%",
|
||||
multiple=True,
|
||||
accept={
|
||||
"image/png": [".png"],
|
||||
"image/jpeg": [".jpg", ".jpeg"],
|
||||
"image/webp": [".webp"],
|
||||
"image/tiff": [".tif", ".tiff"],
|
||||
},
|
||||
#accept={
|
||||
# "image/png": [".png"],
|
||||
# "image/jpeg": [".jpg", ".jpeg"],
|
||||
# "image/webp": [".webp"],
|
||||
# "image/tiff": [".tif", ".tiff"],
|
||||
#},
|
||||
margin_top="50px",
|
||||
style={"align-self": "center"},
|
||||
spacing="2em",
|
||||
@ -48,7 +49,7 @@ def settings() -> rx.Component:
|
||||
rx.box(
|
||||
rx.button("Załaduj zdjęcie",
|
||||
on_click=lambda: State.handle_upload(rx.upload_files()),
|
||||
color="rgba(47, 187, 74,255)",width="90%"),
|
||||
color="rgba(47, 187, 74,255)"),
|
||||
rx.alert_dialog(
|
||||
rx.alert_dialog_overlay(
|
||||
rx.alert_dialog_content(
|
||||
@ -57,12 +58,26 @@ def settings() -> rx.Component:
|
||||
rx.alert_dialog_footer(
|
||||
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
||||
on_click=State.toggle_show(),
|
||||
)
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
is_open=State.show,
|
||||
),
|
||||
rx.alert_dialog(
|
||||
rx.alert_dialog_overlay(
|
||||
rx.alert_dialog_content(
|
||||
rx.alert_dialog_header("Nieprawidłowe rozszerzenie pliku"),
|
||||
rx.alert_dialog_body("Dozwolone rozszerzenia plików to: png, jpg, webp, tiff."),
|
||||
rx.alert_dialog_footer(
|
||||
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
||||
on_click=State.toggle_extension_alert(),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
is_open=State.show_extension_alert,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import reflex as rx
|
||||
import os
|
||||
import stat
|
||||
from blurme import styles
|
||||
import asyncio
|
||||
from graphics.image_modification import blur_boxes_on_image
|
||||
@ -17,8 +18,10 @@ class State(rx.State):
|
||||
show: bool = False
|
||||
def toggle_show(self):
|
||||
self.show = not self.show
|
||||
# Dark mode status
|
||||
#dark_mode: bool = False
|
||||
|
||||
show_extension_alert: bool = False
|
||||
def toggle_extension_alert(self):
|
||||
self.show_extension_alert = not self.show_extension_alert
|
||||
|
||||
def change(self):
|
||||
self.show = not (self.show)
|
||||
@ -30,6 +33,8 @@ class State(rx.State):
|
||||
files: The uploaded files.
|
||||
"""
|
||||
max_files_limit = 5
|
||||
acceptable_extensions = {"png", "jpg", "jpeg", "webp", "tif", "tiff"}
|
||||
|
||||
if len(self.img) + len(files) > max_files_limit:
|
||||
self.toggle_show()
|
||||
return
|
||||
@ -39,11 +44,17 @@ class State(rx.State):
|
||||
upload_data = await file.read()
|
||||
outfile = rx.get_asset_path(file.filename)
|
||||
|
||||
extension = file.filename.split(".")[-1]
|
||||
|
||||
if extension.lower() not in acceptable_extensions:
|
||||
self.toggle_extension_alert()
|
||||
return
|
||||
|
||||
# Save the file.
|
||||
with open(outfile, "wb") as file_object:
|
||||
file_object.write(upload_data)
|
||||
|
||||
# Update the img var.
|
||||
# Update the img var.
|
||||
self.img.append(file.filename)
|
||||
|
||||
self.img = self.img
|
||||
|
Loading…
Reference in New Issue
Block a user