From b75d1e5574162c7947a1f9541ff045708b3f0ed8 Mon Sep 17 00:00:00 2001 From: zhouchengrong Date: Mon, 22 Jul 2024 11:09:06 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=20=E5=A4=84=E7=90=86=E5=A4=9A=E5=B1=82s?= =?UTF-8?q?ketch=20design=E5=87=BA=E7=8E=B0=E7=9A=84=E5=86=85=E6=90=AD?= =?UTF-8?q?=E8=B6=8A=E7=95=8C=E9=97=AE=E9=A2=98=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/service/design/utils/synthesis_item.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/service/design/utils/synthesis_item.py b/app/service/design/utils/synthesis_item.py index 7bedbe6..1b0c64f 100644 --- a/app/service/design/utils/synthesis_item.py +++ b/app/service/design/utils/synthesis_item.py @@ -65,8 +65,12 @@ def synthesis(data, size): try: all_mask_shape = (size[1], size[0]) - top_outer_mask = np.zeros(all_mask_shape, dtype=np.uint8) - bottom_outer_mask = np.zeros(all_mask_shape, dtype=np.uint8) + body_mask = None + for d in data: + if d['name'] == 'body': + body_mask = d['image'].split()[3] + top_outer_mask = np.array(body_mask) + bottom_outer_mask = np.array(body_mask) top = True bottom = True @@ -101,10 +105,10 @@ def synthesis(data, size): if layer['name'] != "body": test_image = Image.new('RGBA', size, (0, 0, 0, 0)) test_image.paste(layer['image'], (layer['position'][1], layer['position'][0]), layer['image']) - # mask_data = np.where(all_mask > 0, 255, 0).astype(np.uint8) - # mask_alpha = Image.fromarray(mask_data) - # cropped_image = Image.composite(test_image, Image.new("RGBA", test_image.size, (255, 255, 255, 0)), mask_alpha) - base_image.paste(test_image, (0, 0), test_image) + mask_data = np.where(all_mask > 0, 255, 0).astype(np.uint8) + mask_alpha = Image.fromarray(mask_data) + cropped_image = Image.composite(test_image, Image.new("RGBA", test_image.size, (255, 255, 255, 0)), mask_alpha) + base_image.paste(test_image, (0, 0), cropped_image) else: base_image.paste(layer['image'], (layer['position'][1], layer['position'][0]), layer['image'])