getstickers 修复转换 png 时锯齿过于严重的问题。

This commit is contained in:
xtaodada 2021-07-01 10:31:29 +08:00
parent 9f25218a64
commit 35a27cd07b
No known key found for this signature in database
GPG Key ID: EE4DC37B55E24736
2 changed files with 14 additions and 3 deletions

View File

@ -69,8 +69,7 @@ async def getstickers(context):
animated = import_tgs(os.path.join(path, file))
export_gif(animated, os.path.join(path, file)[:-3] + 'gif')
elif file_ext_ns_ion == 'webp':
im = Image.open(os.path.join(path, file)).convert('RGB')
im.save(os.path.join(path, file)[:-4] + 'png', 'png')
convert_png(os.path.join(path, file))
pending_tasks = [
asyncio.ensure_future(
@ -143,3 +142,15 @@ def zipdir(path, ziph):
for file in files:
ziph.write(os.path.join(root, file))
os.remove(os.path.join(root, file))
def convert_png(path):
im = Image.open(path)
im.load()
alpha = im.split()[-1]
im = im.convert('RGB').convert('P', palette=Image.ADAPTIVE, colors=255)
mask = Image.eval(alpha, lambda a: 255 if a <=128 else 0)
im.paste(255, mask)
new_path = path.replace(".webp", ".png")
im.save(new_path, transparency=255)
return new_path

View File

@ -532,7 +532,7 @@
},
{
"name": "getstickers",
"version": "1.01",
"version": "1.02",
"section": "chat",
"maintainer": "xtaodada",
"size": "5.4 kb",