Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE-2-感觉方形头像不如圆形的好看 #5

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
media
assets
assets.bak
__pycache__
2 changes: 1 addition & 1 deletion scene.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from manim import *
from pathlib import Path
from fetch_data import fetch_char_data
from scripts.fetch_data import fetch_char_data

class ArkVis(Scene):
def construct(self):
Expand Down
5 changes: 4 additions & 1 deletion fetch_data.py → scripts/fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,7 @@ def fetch_char_data() -> List[CHAR_DATA]:
elif kv['key'] == 'max_hp':
char_info['maxHp'] += kv['value']

return [(c['atk'], c['def'], c['maxHp'], f"assets/images/{c['name']}.png") for c in char_table.values()]
return [(c['atk'], c['def'], c['maxHp'], f"assets/images/{c['name']}.png") for c in char_table.values()]

if __name__ == "__main__":
fetch_char_data()
31 changes: 31 additions & 0 deletions scripts/make_avatar_circle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from PIL import Image, ImageDraw, ImageChops
import logging

def crop_to_circle(image_path, output_path):
# 打开图片并转换为RGBA模式
img = Image.open(image_path).convert("RGBA")

# 创建一个相同尺寸的黑色
mask = Image.new("L", img.size, 0)

# 绘制白色圆形蒙版
draw = ImageDraw.Draw(mask)
draw.ellipse([(0, 0), img.size], fill=255, width=0)

# 把圆形内部,原图中的透明部分正确的附加到蒙版上去
mask = ImageChops.multiply(mask, img.split()[-1])

# 将蒙版应用到图片上
img.putalpha(mask)

# 将图像裁剪成圆形并保存
img.save(output_path, "PNG")

def make_avatar_circle():
from fetch_data import IMAGE_DIR
for avatar_path in IMAGE_DIR.glob("*.png"):
logging.debug(f"Cropping {avatar_path.as_posix()} to circle format.")
crop_to_circle(avatar_path.as_posix(), avatar_path.as_posix())

if __name__ == '__main__':
make_avatar_circle()