Skip to content

Commit

Permalink
feat: five inch (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeyi-Lin authored Sep 25, 2024
1 parent 5959376 commit 5543fba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
10 changes: 5 additions & 5 deletions demo/locales.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@
"label": "Layout photo",
},
"zh": {
"label": "六寸排版照",
"label": "排版照",
},
"ja": {
"label": "レイアウト写真",
Expand Down Expand Up @@ -670,22 +670,22 @@
"plugin": {
"en": {
"label": "🤖Plugin",
"choices": ["Face Alignment", "Layout Photo Crop Line", "JPEG Format"],
"choices": ["Face Alignment", "Layout Photo Crop Line", "JPEG Format", "Five Inch Paper"],
"value": ["Layout Photo Crop Line"]
},
"zh": {
"label": "🤖插件",
"choices": ["人脸旋转对齐", "排版照裁剪线", "JPEG格式"],
"choices": ["人脸旋转对齐", "排版照裁剪线", "JPEG格式", "五寸相纸"],
"value": ["排版照裁剪线"]
},
"ja": {
"label": "🤖プラグイン",
"choices": ["顔の整列", "レイアウト写真の切り取り線", "JPEGフォーマット"],
"choices": ["顔の整列", "レイアウト写真の切り取り線", "JPEGフォーマット", "五寸相紙"],
"value": ["レイアウト写真の切り取り線"]
},
"ko": {
"label": "🤖플러그인",
"choices": ["얼굴 정렬", "레이아웃 사진 자르기 선", "JPEG 포맷"],
"choices": ["얼굴 정렬", "레이아웃 사진 자르기 선", "JPEG 포맷", "오렌지 사진"],
"value": ["레이아웃 사진 자르기 선"]
},
},
Expand Down
16 changes: 15 additions & 1 deletion demo/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,29 @@ def process(
render_option
)
# 读取插件选项
# 人脸对齐选项
if LOCALES["plugin"][language]["choices"][0] in plugin_option:
face_alignment_option = True
else:
face_alignment_option = False
# 排版裁剪线选项
if LOCALES["plugin"][language]["choices"][1] in plugin_option:
layout_photo_crop_line_option = True
else:
layout_photo_crop_line_option = False
# JPEG格式选项
if LOCALES["plugin"][language]["choices"][2] in plugin_option:
jpeg_format_option = True
else:
jpeg_format_option = False
# 五寸相纸选项
if LOCALES["plugin"][language]["choices"][3] in plugin_option:
five_inch_option = True
else:
five_inch_option = False

idphoto_json = self._initialize_idphoto_json(
mode_option, color_option, render_option_index, image_kb_options, layout_photo_crop_line_option, jpeg_format_option
mode_option, color_option, render_option_index, image_kb_options, layout_photo_crop_line_option, jpeg_format_option, five_inch_option
)

# 处理尺寸模式
Expand Down Expand Up @@ -169,6 +177,7 @@ def _initialize_idphoto_json(
image_kb_options,
layout_photo_crop_line_option,
jpeg_format_option,
five_inch_option,
):
"""初始化idphoto_json字典"""
return {
Expand All @@ -180,6 +189,7 @@ def _initialize_idphoto_json(
"custom_image_dpi": None,
"layout_photo_crop_line_option": layout_photo_crop_line_option,
"jpeg_format_option": jpeg_format_option,
"five_inch_option": five_inch_option,
}

# 处理尺寸模式
Expand Down Expand Up @@ -438,6 +448,8 @@ def _generate_image_layout(
typography_arr, typography_rotate = generate_layout_array(
input_height=idphoto_json["size"][0],
input_width=idphoto_json["size"][1],
LAYOUT_HEIGHT= 1205 if not idphoto_json["five_inch_option"] else 1051,
LAYOUT_WIDTH= 1795 if not idphoto_json["five_inch_option"] else 1500,
)

result_image_layout = generate_layout_image(
Expand All @@ -447,6 +459,8 @@ def _generate_image_layout(
height=idphoto_json["size"][0],
width=idphoto_json["size"][1],
crop_line=idphoto_json["layout_photo_crop_line_option"],
LAYOUT_HEIGHT=1205 if not idphoto_json["five_inch_option"] else 1051,
LAYOUT_WIDTH=1795 if not idphoto_json["five_inch_option"] else 1500,
)

return result_image_layout, True
Expand Down
14 changes: 6 additions & 8 deletions hivision/creator/layout_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,8 @@ def judge_layout(
return layout_mode, centerBlockWidth_1, centerBlockHeight_1


def generate_layout_array(input_height, input_width):
def generate_layout_array(input_height, input_width, LAYOUT_WIDTH=1795, LAYOUT_HEIGHT=1205):
# 1.基础参数表
LAYOUT_WIDTH = 1746
LAYOUT_HEIGHT = 1180
PHOTO_INTERVAL_H = 30 # 证件照与证件照之间的垂直距离
PHOTO_INTERVAL_W = 30 # 证件照与证件照之间的水平距离
SIDES_INTERVAL_H = 50 # 证件照与画布边缘的垂直距离
Expand Down Expand Up @@ -118,12 +116,12 @@ def generate_layout_array(input_height, input_width):


def generate_layout_image(
input_image, typography_arr, typography_rotate, width=295, height=413, crop_line:bool=False,
input_image, typography_arr, typography_rotate, width=295, height=413,
crop_line:bool=False,
LAYOUT_WIDTH=1795,
LAYOUT_HEIGHT=1205,
):
# 定义画布的宽度和高度
LAYOUT_WIDTH = 1746
LAYOUT_HEIGHT = 1180


# 创建一个白色背景的空白画布
white_background = np.zeros([LAYOUT_HEIGHT, LAYOUT_WIDTH, 3], np.uint8)
white_background.fill(255)
Expand Down

0 comments on commit 5543fba

Please sign in to comment.