Added image placeholder if cant retrieve it

This commit is contained in:
Joan
2023-06-28 13:26:31 +02:00
parent a40f55ca4e
commit 243d0ba749
3 changed files with 11 additions and 5 deletions

View File

@@ -40,7 +40,10 @@ def create_image(product_id, price):
draw.text(((width / 6) * 5 - wtext / 2, height / 2 - htext / 2), price, (0, 0, 0), font=font)
draw.rectangle([15, 15, width - 15, height - 15], width = 15, outline="#20e163")
# ponemos la imagen del producto en la parte izquierda y se redimensiona dependiendo de lo ancho
product_image = Image.open(f"/app/data/images/products/{product_id}.jpg")
try:
product_image = Image.open(f"/app/data/images/products/{product_id}.jpg")
except:
product_image = Image.open(f"/app/data/images/placeholder.jpg")
hpercent = (baseheight / float(product_image.size[1]))
wsize = int((float(product_image.size[0]) * float(hpercent)))
if wsize < wlimit: