兼容pillow >=10 (#484)

This commit is contained in:
Cathgao 2023-11-06 16:27:23 +08:00 committed by GitHub
parent ae96cb809a
commit 20faac3883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 10 deletions

View File

@ -92,9 +92,9 @@ async def draw_map(name: str, map_: str):
map_img.paste(point_icon, (point_trans[0] - 16, point_trans[1] - 16), point_icon) map_img.paste(point_icon, (point_trans[0] - 16, point_trans[1] - 16), point_icon)
scale_f = map_img.width / map_img.height scale_f = map_img.width / map_img.height
if scale_f > 980 / 850: if scale_f > 980 / 850:
map_img = map_img.resize((math.ceil(850 * scale_f), 850), Image.ANTIALIAS) map_img = map_img.resize((math.ceil(850 * scale_f), 850), Image.LANCZOS)
else: else:
map_img = map_img.resize((980, math.ceil(980 / scale_f)), Image.ANTIALIAS) map_img = map_img.resize((980, math.ceil(980 / scale_f)), Image.LANCZOS)
map_img = map_img.crop((0, 0, 980, 850)) map_img = map_img.crop((0, 0, 980, 850))
map_img = ImageOps.expand(map_img, border=4, fill='#633da3') map_img = ImageOps.expand(map_img, border=4, fill='#633da3')
total_img = PMImage(await load_image(RESOURCE_BASE_PATH / 'genshin_map' / 'bg.png')) total_img = PMImage(await load_image(RESOURCE_BASE_PATH / 'genshin_map' / 'bg.png'))
@ -150,7 +150,7 @@ async def get_full_map(names: List[str], map_: str):
for i, points in enumerate(resources_points): for i, points in enumerate(resources_points):
resource_icon = box_icon.copy() resource_icon = box_icon.copy()
resource_icon.alpha_composite(await aiorequests.get_img(resources[i].icon, size=(90, 90)), (28, 15)) resource_icon.alpha_composite(await aiorequests.get_img(resources[i].icon, size=(90, 90)), (28, 15))
resource_icon = resource_icon.resize((48, 48), Image.ANTIALIAS) resource_icon = resource_icon.resize((48, 48), Image.LANCZOS)
if len(points) >= 3: if len(points) >= 3:
group_point = img.k_means_points(points, 2000) group_point = img.k_means_points(points, 2000)
else: else:

View File

@ -194,7 +194,7 @@ class PMImage:
height = height[0] height = height[0]
self.draw.text((width, height), text, color, font) self.draw.text((width, height), text, color, font)
elif align in ['center', 'right']: elif align in ['center', 'right']:
w, h = self.draw.textsize(text, font) _, _, w, h = self.draw.textbbox((0, 0), text, font)
if align == 'center': if align == 'center':
w = width[0] + (width[1] - width[0] - w) / 2 if isinstance(width, tuple) else width w = width[0] + (width[1] - width[0] - w) / 2 if isinstance(width, tuple) else width
h = height[0] + (height[1] - height[0] - h) / 2 if isinstance(height, tuple) else height h = height[0] + (height[1] - height[0] - h) / 2 if isinstance(height, tuple) else height
@ -574,9 +574,9 @@ async def load_image(
img = img.convert(mode) img = img.convert(mode)
if size: if size:
if isinstance(size, float): if isinstance(size, float):
img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.ANTIALIAS) img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.LANCZOS)
elif isinstance(size, tuple): elif isinstance(size, tuple):
img = img.resize(size, Image.ANTIALIAS) img = img.resize(size, Image.LANCZOS)
if crop: if crop:
img = img.crop(crop) img = img.crop(crop)
return img return img

View File

@ -51,9 +51,9 @@ class MessageBuild:
img = img.image img = img.image
if size: if size:
if isinstance(size, float): if isinstance(size, float):
img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.ANTIALIAS) img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.LANCZOS)
elif isinstance(size, tuple): elif isinstance(size, tuple):
img = img.resize(size, Image.ANTIALIAS) img = img.resize(size, Image.LANCZOS)
if crop: if crop:
img = img.crop(crop) img = img.crop(crop)
if mode: if mode:

View File

@ -125,9 +125,9 @@ class aiorequests:
img = Image.open(BytesIO(resp)) img = Image.open(BytesIO(resp))
if size: if size:
if isinstance(size, float): if isinstance(size, float):
img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.ANTIALIAS) img = img.resize((int(img.size[0] * size), int(img.size[1] * size)), Image.LANCZOS)
elif isinstance(size, tuple): elif isinstance(size, tuple):
img = img.resize(size, Image.ANTIALIAS) img = img.resize(size, Image.LANCZOS)
if mode: if mode:
img = img.convert(mode) img = img.convert(mode)
if crop: if crop: