Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyi-Lin committed Sep 14, 2024
2 parents 20801a2 + 5928ead commit 2b0b01b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
14 changes: 11 additions & 3 deletions demo/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def process(
):
# 初始化参数
top_distance_min = top_distance_max - 0.02
# 得到render_option在LOCALES["render_mode"][language]["choices"]中的索引
render_option_index = LOCALES["render_mode"][language]["choices"].index(
render_option
)
idphoto_json = self._initialize_idphoto_json(
mode_option, color_option, render_option, image_kb_options
mode_option, color_option, render_option_index, image_kb_options
)

# 处理尺寸模式
Expand Down Expand Up @@ -296,7 +300,7 @@ def _process_generated_photo(
def _render_background(self, result_image_standard, result_image_hd, idphoto_json):
"""渲染背景"""
render_modes = {0: "pure_color", 1: "updown_gradient", 2: "center_gradient"}
render_mode = render_modes.get(idphoto_json["render_mode"], "pure_color")
render_mode = render_modes[idphoto_json["render_mode"]]

result_image_standard = np.uint8(
add_background(
Expand Down Expand Up @@ -391,7 +395,11 @@ def _resize_image_if_needed(self, result_image_standard, idphoto_json):
result_image_standard,
output_image_path,
idphoto_json["custom_image_kb"],
dpi=idphoto_json["custom_image_dpi"],
dpi=(
idphoto_json["custom_image_dpi"]
if idphoto_json["custom_image_dpi"]
else 300
),
)
return output_image_path
# 如果只设置了dpi
Expand Down
31 changes: 17 additions & 14 deletions demo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,24 @@ def change_language(language):
),
}

def change_visibility(option, lang, locales_key, custom_component):
return {
custom_component: gr.update(
visible=option == LOCALES[locales_key][lang]["choices"][-1]
)
}

def change_color(colors, lang):
if colors == LOCALES["bg_color"][lang]["choices"][-1]:
return {custom_color: gr.update(visible=True)}
else:
return {custom_color: gr.update(visible=False)}
return change_visibility(colors, lang, "bg_color", custom_color)

def change_size_mode(size_option_item, lang):
if size_option_item == LOCALES["size_mode"][lang]["choices"][2]:
choices = LOCALES["size_mode"][lang]["choices"]
if size_option_item == choices[2]:
return {
custom_size: gr.update(visible=True),
size_list_row: gr.update(visible=False),
}
elif size_option_item == LOCALES["size_mode"][lang]["choices"][1]:
elif size_option_item == choices[1]:
return {
custom_size: gr.update(visible=False),
size_list_row: gr.update(visible=False),
Expand All @@ -496,16 +501,14 @@ def change_size_mode(size_option_item, lang):
}

def change_image_kb(image_kb_option, lang):
if image_kb_option == LOCALES["image_kb"][lang]["choices"][1]:
return {custom_image_kb_size: gr.update(visible=True)}
else:
return {custom_image_kb_size: gr.update(visible=False)}
return change_visibility(
image_kb_option, lang, "image_kb", custom_image_kb_size
)

def change_image_dpi(image_dpi_option, lang):
if image_dpi_option == LOCALES["image_dpi"][lang]["choices"][1]:
return {custom_image_dpi_size: gr.update(visible=True)}
else:
return {custom_image_dpi_size: gr.update(visible=False)}
return change_visibility(
image_dpi_option, lang, "image_dpi", custom_image_dpi_size
)

# ---------------- 绑定事件 ----------------
# 语言切换
Expand Down

0 comments on commit 2b0b01b

Please sign in to comment.