Last active
March 28, 2022 21:06
-
-
Save shivangrathore/fcd8df61de3c3701a50e7bce4d086e63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont | |
import numpy | |
level = 1 | |
rank = 5 | |
final_xp = 1000 | |
xp = 400 | |
user_name = "WiperR" | |
discriminator = "#3131" | |
background = Image.new("RGB", (1000, 240)) | |
logo = Image.open("logo.png").resize((200, 200)) | |
bigsize = (logo.size[0] * 3, logo.size[1] * 3) | |
mask = Image.new("L", bigsize, 0) | |
draw = ImageDraw.Draw(mask) | |
draw.ellipse((0, 0) + bigsize, 255) | |
# Black Circle | |
draw.ellipse((140 * 3, 140 * 3, 189 * 3, 189 * 3), 0) | |
mask = mask.resize(logo.size, Image.ANTIALIAS) | |
logo.putalpha(mask) | |
background.paste(logo, (20, 20), mask=logo) | |
# # Black Circle | |
draw = ImageDraw.Draw(background, "RGB") | |
# draw.ellipse((160, 160, 208, 208), fill="#000") | |
# Green Circle (Discord Status Colours) | |
draw.ellipse((162, 162, 206, 206), fill="#43B581") | |
# Working with Fonts | |
big_font = ImageFont.FreeTypeFont("ABeeZee-Regular.otf", 60) | |
medium_font = ImageFont.FreeTypeFont("ABeeZee-Regular.otf", 40) | |
small_font = ImageFont.FreeTypeFont("ABeeZee-Regular.otf", 30) | |
# Placing Right Upper Part | |
text_size = draw.textsize(str(level), font=big_font) | |
offset_x = 1000 - 15 - text_size[0] | |
offset_y = 10 | |
draw.text((offset_x, offset_y), str(level), font=big_font, fill="#11ebf2") | |
text_size = draw.textsize("LEVEL", font=small_font) | |
offset_x -= text_size[0] + 5 | |
draw.text((offset_x, offset_y + 27), "LEVEL", font=small_font, fill="#11ebf2") | |
text_size = draw.textsize(f"#{rank}", font=big_font) | |
offset_x -= text_size[0] + 15 | |
draw.text((offset_x, offset_y), f"#{rank}", font=big_font, fill="#fff") | |
text_size = draw.textsize("RANK", font=small_font) | |
offset_x -= text_size[0] + 5 | |
draw.text((offset_x, offset_y + 27), "RANK", font=small_font, fill="#fff") | |
# Empty Progress Bar (Gray) | |
bar_offset_x = 320 | |
bar_offset_y = 160 | |
bar_offset_x_1 = 950 | |
bar_offset_y_1 = 200 | |
circle_size = bar_offset_y_1 - bar_offset_y # Diameter | |
# Progress Bar | |
draw.rectangle((bar_offset_x, bar_offset_y, bar_offset_x_1, bar_offset_y_1), fill="#727175") | |
# Left Circle | |
draw.ellipse( | |
(bar_offset_x - circle_size // 2, bar_offset_y, bar_offset_x + circle_size // 2, bar_offset_y_1), fill="#727175" | |
) | |
# Right Circle | |
draw.ellipse( | |
(bar_offset_x_1 - circle_size // 2, bar_offset_y, bar_offset_x_1 + circle_size // 2, bar_offset_y_1), fill="#727175" | |
) | |
# Filling Bar | |
bar_length = bar_offset_x_1 - bar_offset_x | |
progress = (final_xp - xp) * 100 / final_xp | |
progress = 100 - progress | |
progress_bar_length = round(bar_length * progress / 100) | |
bar_offset_x_1 = bar_offset_x + progress_bar_length | |
# Progress Bar | |
draw.rectangle((bar_offset_x, bar_offset_y, bar_offset_x_1, bar_offset_y_1), fill="#11ebf2") | |
# Left Circle | |
draw.ellipse( | |
(bar_offset_x - circle_size // 2, bar_offset_y, bar_offset_x + circle_size // 2, bar_offset_y_1), fill="#11ebf2" | |
) | |
# Right Circle | |
draw.ellipse( | |
(bar_offset_x_1 - circle_size // 2, bar_offset_y, bar_offset_x_1 + circle_size // 2, bar_offset_y_1), fill="#11ebf2" | |
) | |
text_size = draw.textsize(f"/ {final_xp} XP", font=small_font) | |
offset_x = 950 - text_size[0] | |
offset_y = bar_offset_y - text_size[1] - 10 | |
draw.text((offset_x, offset_y), f"/ {final_xp:,} XP", font=small_font, fill="#727175") | |
text_size = draw.textsize(f"{xp:,}", font=small_font) | |
offset_x -= text_size[0] + 8 | |
draw.text((offset_x, offset_y), f"{xp:,}", font=small_font, fill="#fff") | |
# Blitting Name | |
text_size = draw.textsize(user_name, font=medium_font) | |
offset_x = bar_offset_x | |
offset_y = bar_offset_y - text_size[1] - 5 | |
draw.text((offset_x, offset_y), user_name, font=medium_font, fill="#fff") | |
# Discriminator | |
offset_x += text_size[0] + 5 | |
offset_y += 10 | |
draw.text((offset_x, offset_y), discriminator, font=small_font, fill="#727175") | |
background.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment