Answer the question
In order to leave comments, you need to log in
Why doesn't the avatar appear on the photo using PIL?
The code works, but the avatar does not appear on the background (blank.jpg)
elif "цит" in body.lower():
body.split(' ', 1)
message = body.split(' ', 1)[1]
# определяете шрифт
api = vk_api.VkApi(token=token)
u_name = api.method("users.get", { "user_ids": id, "fields": "first_name"})
user_ava = api.method("users.get", { "user_ids": id, "fields": "photo_max"})
rec.urlretrieve(user_ava[0]["photo_max"], "user_ava.jpg")
img_avatar = Image.open("user_ava.jpg").convert('RGBA')
user_name = u_name[0]["first_name"]
user_surname = u_name[0]["last_name"]
font = ImageFont.truetype("uni_sans_heavy.ttf", 30)
font2 = ImageFont.truetype("uni_sans_heavy.ttf", 30)
# определяете положение текста на картинке
text2_position = (330, 80)
text_position = (24, 330)
##ava_position = (220, 70)
# цвет текста, RGB
text_color = (0,0,0)
text2_color = (0,0,0)
# собственно, сам текст
text2 = '« ' + str(message) + ' »'
name = '© ' + str(user_name) + " " + str(user_surname)
# загружаете фоновое изображение
img = Image.open('blank.jpg')
# определяете объект для рисования
draw = ImageDraw.Draw(img)
# добавляем текст
draw.text(text_position, name, text_color, font, img_avatar)
draw.text(text2_position, text2, text2_color, font2)
# сохраняем новое изображение
img.save('blank_with_text.jpg')
Answer the question
In order to leave comments, you need to log in
After uploading 'blank.jpg' add an avatar insert to it with the required coordinates
img = Image.open('blank.jpg')
img.paste(img_avatar, (100, 100))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question