Spaces:
Sleeping
Sleeping
Update src/pyscripts/img_process.py
Browse files- src/pyscripts/img_process.py +47 -12
src/pyscripts/img_process.py
CHANGED
|
@@ -531,13 +531,13 @@ def write_rundown(BACKGROUND_COLOR, rundown, point_bar, H_PADDING_RATION, bg_wid
|
|
| 531 |
return background
|
| 532 |
|
| 533 |
|
| 534 |
-
def write_person_line(background, person, H_PADDING_RATION, start_y, photo_size_ratio):
|
| 535 |
bg_width = background.size[0]
|
| 536 |
text = person["name"]
|
| 537 |
-
font_size =
|
| 538 |
font_path = font_path_zihun59
|
| 539 |
alignment = "left"
|
| 540 |
-
pioneer_part_width = H_PADDING_RATION * bg_width +
|
| 541 |
|
| 542 |
radius = int(photo_size_ratio * bg_width)
|
| 543 |
if person["photo_link"] != "":
|
|
@@ -546,10 +546,10 @@ def write_person_line(background, person, H_PADDING_RATION, start_y, photo_size_
|
|
| 546 |
|
| 547 |
person["title"] = person["title"].split("\n")
|
| 548 |
|
| 549 |
-
name_padding = 50
|
| 550 |
-
title_padding = 20
|
| 551 |
|
| 552 |
-
people_text_y = start_y + (2 * radius - font_size - name_padding -
|
| 553 |
conference_rundown_people_name, background, next_height = write_text(
|
| 554 |
text,
|
| 555 |
font_path,
|
|
@@ -561,7 +561,7 @@ def write_person_line(background, person, H_PADDING_RATION, start_y, photo_size_
|
|
| 561 |
alignment=alignment
|
| 562 |
)
|
| 563 |
next_height += name_padding
|
| 564 |
-
font_size =
|
| 565 |
font_path = font_path_notosansM
|
| 566 |
# pioneer_part_width = H_PADDING_RATION * bg_width + round_photo.size[1] + font_size
|
| 567 |
for i, text in enumerate(person["title"]):
|
|
@@ -585,8 +585,9 @@ def write_round_photo(background, person, start_x, start_y, radius):
|
|
| 585 |
res = requests.get(person["photo_link"])
|
| 586 |
photo = Image.open(io.BytesIO(res.content)).convert("RGBA")
|
| 587 |
width, height = photo.size
|
| 588 |
-
circle_center = (width // 2, height //
|
| 589 |
-
circle_radius = min(width, height //
|
|
|
|
| 590 |
round_photo = crop_round_img(photo, circle_center, circle_radius)
|
| 591 |
round_photo = round_photo.resize((radius*2, radius*2))
|
| 592 |
background = embed_image(background, round_photo, offset_y=start_y-radius, offset_x=start_x-radius)
|
|
@@ -713,7 +714,7 @@ def getGuestComposePoster(conference_name, conference_eng_name, people):
|
|
| 713 |
max_height=700,
|
| 714 |
alignment="medium",
|
| 715 |
)
|
| 716 |
-
|
| 717 |
people = [p for p in people if p["photo_link"] != ""]
|
| 718 |
for (i, person) in enumerate(people):
|
| 719 |
background = write_person_card(background, card, person, H_PADDING + card.size[0] * (i % 3), card.height * (i // 3))
|
|
@@ -777,6 +778,37 @@ def write_person_card(background, card, person, H_PADDING, start_y):
|
|
| 777 |
return background
|
| 778 |
|
| 779 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
if __name__ == "__main__":
|
| 781 |
# image_path = 'src/assets/邀请函封面.jpg' # 替换为你的图片文件路径
|
| 782 |
# text_to_write = "你好,世界!"
|
|
@@ -827,7 +859,7 @@ if __name__ == "__main__":
|
|
| 827 |
|
| 828 |
name, titles = "王千里", "全国政协文员\n好好先生"
|
| 829 |
PHOTO_LINK = "https://weboffice-temporary.ks3-cn-beijing.wpscdn.cn/thumbnail/tpcdnbPEKEJ3ge831dSHEd3_100.png?Expires=1720890000&KSSAccessKeyId=AKLTmoJhggaFT1CHuozGZqbC&Signature=jeKkEy%2BTx3BAMNzqrmjUbg6uBK8%3D&response-cache-control=public%2Cmax-age%3D86400"
|
| 830 |
-
ORIGINAL_PHOTO_LINK = "https://weboffice-temporary.ks3-cn-beijing.wpscdn.cn/thumbnail/
|
| 831 |
|
| 832 |
conference_name = "教育行业规范管理发展论坛"
|
| 833 |
conference_name_eng = "2024 World Education Conference"
|
|
@@ -960,7 +992,7 @@ if __name__ == "__main__":
|
|
| 960 |
# photo = Image.open(io.BytesIO(res.content)).convert("RGBA")
|
| 961 |
|
| 962 |
# make_exhibitor_poster(LOGO_LINK, slogan_list[SLOGAN_ID], text_list[TEXT_ID])
|
| 963 |
-
make_guest_poster(name, "", "", ORIGINAL_PHOTO_LINK, titles)
|
| 964 |
|
| 965 |
# make_conference_poster(conference_name, conference_name_eng, conference_name_full, conference_info, conference_rundown)
|
| 966 |
# 定义圆心和半径
|
|
@@ -973,3 +1005,6 @@ if __name__ == "__main__":
|
|
| 973 |
|
| 974 |
|
| 975 |
# getGuestComposePoster("全球教育者公论教育", "EDUCATORS AROUND THE GLOBE TALKING ABOUT EDUCATION", people)
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
return background
|
| 532 |
|
| 533 |
|
| 534 |
+
def write_person_line(background, person, H_PADDING_RATION, start_y, photo_size_ratio, scale=1, text_start_padding=120, name_font_size=120, title_font_size=80):
|
| 535 |
bg_width = background.size[0]
|
| 536 |
text = person["name"]
|
| 537 |
+
font_size = name_font_size * scale
|
| 538 |
font_path = font_path_zihun59
|
| 539 |
alignment = "left"
|
| 540 |
+
pioneer_part_width = H_PADDING_RATION * bg_width + text_start_padding * scale
|
| 541 |
|
| 542 |
radius = int(photo_size_ratio * bg_width)
|
| 543 |
if person["photo_link"] != "":
|
|
|
|
| 546 |
|
| 547 |
person["title"] = person["title"].split("\n")
|
| 548 |
|
| 549 |
+
name_padding = 50 * scale
|
| 550 |
+
title_padding = 20 * scale
|
| 551 |
|
| 552 |
+
people_text_y = start_y + (2 * radius - font_size - name_padding - title_font_size * scale * len(person["title"])) // 2
|
| 553 |
conference_rundown_people_name, background, next_height = write_text(
|
| 554 |
text,
|
| 555 |
font_path,
|
|
|
|
| 561 |
alignment=alignment
|
| 562 |
)
|
| 563 |
next_height += name_padding
|
| 564 |
+
font_size = title_font_size * scale
|
| 565 |
font_path = font_path_notosansM
|
| 566 |
# pioneer_part_width = H_PADDING_RATION * bg_width + round_photo.size[1] + font_size
|
| 567 |
for i, text in enumerate(person["title"]):
|
|
|
|
| 585 |
res = requests.get(person["photo_link"])
|
| 586 |
photo = Image.open(io.BytesIO(res.content)).convert("RGBA")
|
| 587 |
width, height = photo.size
|
| 588 |
+
circle_center = (width // 2, height // 3)
|
| 589 |
+
circle_radius = min(width//2, height // 3)
|
| 590 |
+
print(width, height, circle_center, circle_radius)
|
| 591 |
round_photo = crop_round_img(photo, circle_center, circle_radius)
|
| 592 |
round_photo = round_photo.resize((radius*2, radius*2))
|
| 593 |
background = embed_image(background, round_photo, offset_y=start_y-radius, offset_x=start_x-radius)
|
|
|
|
| 714 |
max_height=700,
|
| 715 |
alignment="medium",
|
| 716 |
)
|
| 717 |
+
|
| 718 |
people = [p for p in people if p["photo_link"] != ""]
|
| 719 |
for (i, person) in enumerate(people):
|
| 720 |
background = write_person_card(background, card, person, H_PADDING + card.size[0] * (i % 3), card.height * (i // 3))
|
|
|
|
| 778 |
return background
|
| 779 |
|
| 780 |
|
| 781 |
+
def getGuestEScreen(root_type, person):
|
| 782 |
+
template_info = {
|
| 783 |
+
"full": {
|
| 784 |
+
"width": 3328,
|
| 785 |
+
"height": 1152
|
| 786 |
+
},
|
| 787 |
+
"half": {
|
| 788 |
+
"width": 3072,
|
| 789 |
+
"height": 1280
|
| 790 |
+
}
|
| 791 |
+
}
|
| 792 |
+
background = Image.open(f"src/assets/EScreen/{root_type}.jpg")
|
| 793 |
+
bg_width, bg_height = background.size
|
| 794 |
+
scale = bg_width / template_info[root_type]["width"]
|
| 795 |
+
|
| 796 |
+
radius = 600 // 2 * scale
|
| 797 |
+
radius_ratio = radius / bg_width
|
| 798 |
+
H_PADDING_RATION = 0.22
|
| 799 |
+
V_START = bg_height // 2 - radius
|
| 800 |
+
print(background.size)
|
| 801 |
+
|
| 802 |
+
write_person_line(background, person, H_PADDING_RATION, V_START, radius_ratio,
|
| 803 |
+
text_start_padding=200, name_font_size=100, title_font_size=50, scale=scale)
|
| 804 |
+
|
| 805 |
+
img_stream = io.BytesIO()
|
| 806 |
+
background.save(img_stream, format="JPEG")
|
| 807 |
+
img_stream.seek(0)
|
| 808 |
+
if os.path.exists("src/assets/output"):
|
| 809 |
+
background.save("src/assets/output/hall_screen.jpg")
|
| 810 |
+
return img_stream
|
| 811 |
+
|
| 812 |
if __name__ == "__main__":
|
| 813 |
# image_path = 'src/assets/邀请函封面.jpg' # 替换为你的图片文件路径
|
| 814 |
# text_to_write = "你好,世界!"
|
|
|
|
| 859 |
|
| 860 |
name, titles = "王千里", "全国政协文员\n好好先生"
|
| 861 |
PHOTO_LINK = "https://weboffice-temporary.ks3-cn-beijing.wpscdn.cn/thumbnail/tpcdnbPEKEJ3ge831dSHEd3_100.png?Expires=1720890000&KSSAccessKeyId=AKLTmoJhggaFT1CHuozGZqbC&Signature=jeKkEy%2BTx3BAMNzqrmjUbg6uBK8%3D&response-cache-control=public%2Cmax-age%3D86400"
|
| 862 |
+
ORIGINAL_PHOTO_LINK = "https://weboffice-temporary.ks3-cn-beijing.wpscdn.cn/thumbnail/tn6C9byoghgm8cnQYtShMdb_100.jpeg?Expires=1723395600&KSSAccessKeyId=AKLTmoJhggaFT1CHuozGZqbC&Signature=%2BJX%2BaPumafx8mXpV7wfN1Z3FVpA%3D&response-cache-control=public%2Cmax-age%3D86400"
|
| 863 |
|
| 864 |
conference_name = "教育行业规范管理发展论坛"
|
| 865 |
conference_name_eng = "2024 World Education Conference"
|
|
|
|
| 992 |
# photo = Image.open(io.BytesIO(res.content)).convert("RGBA")
|
| 993 |
|
| 994 |
# make_exhibitor_poster(LOGO_LINK, slogan_list[SLOGAN_ID], text_list[TEXT_ID])
|
| 995 |
+
# make_guest_poster(name, "", "", ORIGINAL_PHOTO_LINK, titles)
|
| 996 |
|
| 997 |
# make_conference_poster(conference_name, conference_name_eng, conference_name_full, conference_info, conference_rundown)
|
| 998 |
# 定义圆心和半径
|
|
|
|
| 1005 |
|
| 1006 |
|
| 1007 |
# getGuestComposePoster("全球教育者公论教育", "EDUCATORS AROUND THE GLOBE TALKING ABOUT EDUCATION", people)
|
| 1008 |
+
|
| 1009 |
+
getGuestEScreen("full", conference_rundown[0]["people"][0])
|
| 1010 |
+
|