From ba534a68f12ea80878a0e2df4e61c26fa95242b7 Mon Sep 17 00:00:00 2001 From: phzhik Date: Wed, 11 Oct 2023 22:28:17 +0400 Subject: [PATCH] * Updated preview layout --- store/utils.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/store/utils.py b/store/utils.py index 0388d47..c1a2948 100644 --- a/store/utils.py +++ b/store/utils.py @@ -12,8 +12,8 @@ from poizonstore.settings import BASE_DIR def create_preview(source_image: str, size=None, price_rub=None, title_lines=None): # Create image preview_width, preview_height = 800, 600 - hor_padding = 15 - vert_padding = 50 + hor_padding = 30 + vert_padding = 30 left_block_width = 270 # minimal width canvas_img = Image.new('RGBA', (preview_width, preview_height), color='white') @@ -101,9 +101,9 @@ def create_preview(source_image: str, size=None, price_rub=None, title_lines=Non price_text = format(int(price_rub), ',').replace(',', ' ') price_text = f"{price_text} ₽" price_font = get_font(50) - price_x, price_y = hor_padding + 15, preview_height - 100 + price_x, price_y = hor_padding, preview_height - vert_padding - block_size = draw_text((price_x, price_y), price_text, font=price_font, fill='black') + block_size = draw_text((price_x, price_y), price_text, anchor='ls', font=price_font, fill='black') left_block_width = max(left_block_width, block_size[0] + price_x) # Draw goods image @@ -114,14 +114,18 @@ def create_preview(source_image: str, size=None, price_rub=None, title_lines=Non with Image.open(source_image).convert("RGBA") as img2: img2 = resize_with_ar(img2, (img2_box_w, img2_box_y)) - img2_x = left_block_width + int(img2_box_w / 2) - int(img2.width / 2) - img2_y = 50 + int(img2_box_y / 2) - int(img2.height / 2) + img2_x = left_block_width + int(img2_box_w / 2) - int(img2.width / 2) + hor_padding + img2_y = vert_padding + int(img2_box_y / 2) - int(img2.height / 2) canvas_img.paste(img2, (img2_x, img2_y), mask=img2) # Debug only # img2_box = (img2_x, img2_y, img2_x + img2.width, img2_y + img2.height) # draw.rectangle(img2_box, outline='red', width=2) + # + # left_block_box = (hor_padding, vert_padding, left_block_width, preview_height - 2*vert_padding) + # draw.rectangle(left_block_box, outline='red', width=2) + return canvas_img.convert('RGB') except UnidentifiedImageError: return None