From 5543fba4f17d8fa6bb01ba5ccfa73f12a9412974 Mon Sep 17 00:00:00 2001 From: Ze-Yi LIN <58305964+Zeyi-Lin@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:20:25 +0800 Subject: [PATCH] feat: five inch (#171) --- demo/locales.py | 10 +++++----- demo/processor.py | 16 +++++++++++++++- hivision/creator/layout_calculator.py | 14 ++++++-------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/demo/locales.py b/demo/locales.py index 633a757f..59408e94 100644 --- a/demo/locales.py +++ b/demo/locales.py @@ -546,7 +546,7 @@ "label": "Layout photo", }, "zh": { - "label": "六寸排版照", + "label": "排版照", }, "ja": { "label": "レイアウト写真", @@ -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": ["레이아웃 사진 자르기 선"] }, }, diff --git a/demo/processor.py b/demo/processor.py index 65f06fc5..bed27f62 100644 --- a/demo/processor.py +++ b/demo/processor.py @@ -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 ) # 处理尺寸模式 @@ -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 { @@ -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, } # 处理尺寸模式 @@ -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( @@ -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 diff --git a/hivision/creator/layout_calculator.py b/hivision/creator/layout_calculator.py index 1637ea5f..45763145 100644 --- a/hivision/creator/layout_calculator.py +++ b/hivision/creator/layout_calculator.py @@ -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 # 证件照与画布边缘的垂直距离 @@ -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)