* Updated preview layout
This commit is contained in:
parent
b55e42c90f
commit
ba534a68f1
|
|
@ -12,8 +12,8 @@ from poizonstore.settings import BASE_DIR
|
||||||
def create_preview(source_image: str, size=None, price_rub=None, title_lines=None):
|
def create_preview(source_image: str, size=None, price_rub=None, title_lines=None):
|
||||||
# Create image
|
# Create image
|
||||||
preview_width, preview_height = 800, 600
|
preview_width, preview_height = 800, 600
|
||||||
hor_padding = 15
|
hor_padding = 30
|
||||||
vert_padding = 50
|
vert_padding = 30
|
||||||
left_block_width = 270 # minimal width
|
left_block_width = 270 # minimal width
|
||||||
|
|
||||||
canvas_img = Image.new('RGBA', (preview_width, preview_height), color='white')
|
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 = format(int(price_rub), ',').replace(',', ' ')
|
||||||
price_text = f"{price_text} ₽"
|
price_text = f"{price_text} ₽"
|
||||||
price_font = get_font(50)
|
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)
|
left_block_width = max(left_block_width, block_size[0] + price_x)
|
||||||
|
|
||||||
# Draw goods image
|
# 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:
|
with Image.open(source_image).convert("RGBA") as img2:
|
||||||
img2 = resize_with_ar(img2, (img2_box_w, img2_box_y))
|
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_x = left_block_width + int(img2_box_w / 2) - int(img2.width / 2) + hor_padding
|
||||||
img2_y = 50 + int(img2_box_y / 2) - int(img2.height / 2)
|
img2_y = vert_padding + int(img2_box_y / 2) - int(img2.height / 2)
|
||||||
|
|
||||||
canvas_img.paste(img2, (img2_x, img2_y), mask=img2)
|
canvas_img.paste(img2, (img2_x, img2_y), mask=img2)
|
||||||
|
|
||||||
# Debug only
|
# Debug only
|
||||||
# img2_box = (img2_x, img2_y, img2_x + img2.width, img2_y + img2.height)
|
# img2_box = (img2_x, img2_y, img2_x + img2.width, img2_y + img2.height)
|
||||||
# draw.rectangle(img2_box, outline='red', width=2)
|
# 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')
|
return canvas_img.convert('RGB')
|
||||||
except UnidentifiedImageError:
|
except UnidentifiedImageError:
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user