From bf200b98cf96dcc5c2cca7bb0b7f9c792556de03 Mon Sep 17 00:00:00 2001 From: static Date: Sat, 7 Sep 2024 06:35:01 +0900 Subject: [PATCH 1/2] Fix: profile image rendered bluishly --- main.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.py b/main.py index e779566..2bfbb22 100644 --- a/main.py +++ b/main.py @@ -191,6 +191,11 @@ async def eventInviteHandler(inviterId: str): raise ValueError("eventInviteHandler : Invalid profileImageUrl") img_profile = Image.open(BytesIO(res_profile.content)) + # convert rgb(a) to bgr(a) format (cv2 uses bgr format) + img_profile_array = np.array(img_profile) + img_profile_array[..., :3] = img_profile_array[..., :3][..., ::-1] + img_profile = Image.fromarray(img_profile_array) + # convert inviter information to text text = { "nickname": inviterInfo["nickname"], @@ -214,6 +219,8 @@ async def eventInviteHandler(inviterId: str): draw.text((31, 140), text["message"], font=fonts["eventInvite"]["message"], fill=colors["white"]) # draw profile image + if min(img_profile.size) > 245: + img_profile = img_profile.crop((0, 0, min(img_profile.size), min(img_profile.size))) img_profile = img_profile.resize((245, 245)) scale_factor = 4 # for anti-aliasing From b7ad43b50f19c051597e16f5e354ec69e2815b8f Mon Sep 17 00:00:00 2001 From: static Date: Sat, 7 Sep 2024 06:39:46 +0900 Subject: [PATCH 2/2] Fix: background is always black when threre is alpha channel in profile image --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 2bfbb22..9eb01ae 100644 --- a/main.py +++ b/main.py @@ -203,7 +203,7 @@ async def eventInviteHandler(inviterId: str): } # load background image - img_og = Image.fromarray(images["background.{}.eventInvite".format(event_type)]) + img_og = Image.fromarray(images["background.{}.eventInvite".format(event_type)]).convert("RGBA") draw = ImageDraw.Draw(img_og, "RGBA") # draw nickname