import json
from PIL import Image, ImageDraw, ImageFont
def create_image_from_json(config_file):
with open(config_file) as f:
config = json.load(f)
width = config.get("width", 800)
height = config.get("height", 600)
background_color = config.get("background_color", "white")
user_image = Image.open(config.get("user_image", "user.jpg"))
user_image = user_image.resize((int(width * 0.3), int(height * 0.3)))
font = ImageFont.truetype(config.get("font", "arial.ttf"), size=20)
language_icon_size = int(width * 0.1)
image = Image.new("RGB", (width, height), background_color)
draw = ImageDraw.Draw(image)
user_image_x = int(width * 0.05)
user_image_y = int(height * 0.05)
image.paste(user_image, (user_image_x, user_image_y))
username = config.get("username", "John Doe")
username_x = int(user_image_x + user_image.width + 10)
username_y = int(user_image_y + user_image.height / 2 - font.getsize(username)[1] / 2)
draw.text((username_x, username_y), username, font=font, fill=(0, 0, 0))
programming_languages = config.get("programming_languages", [])
programming_languages_x = int(width * 0.05)
programming_languages_y = int(user_image_y + user_image.height + 20)
for language in programming_languages:
language_icon = Image.open(language.get("icon", "python.png"))
language_icon = language_icon.resize((language_icon_size, language_icon_size))
image.paste(language_icon, (programming_languages_x, programming_languages_y))
programming_languages_x += language_icon.width + 10
return image