CMHopeSunshine / LittlePaimon

小派蒙!基于Nonebot2的原神机器人,包括但不限于UID面板查询、抽卡记录分析、游戏攻略图鉴、实时便签、原石札记、群聊学习、群管等功能。/ LittlePamon! Genshin Impact multifunctional bot based on Nonebot2.
https://docs.paimon.cherishmoon.top
GNU Affero General Public License v3.0
1.15k stars 126 forks source link

get_img 有时获取的图片格式不符合预期(RGBA) #125

Closed Sclock closed 2 years ago

Sclock commented 2 years ago

get_img 有时获取的图片 mode=P ,在进行 alpha_composite 时会报 ValueError: images do not match

经测试可能是链接的问题,问题链接示例:

url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_01.png
url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_02.png

修复方法

强制转换所有获取的图片

weapon_icon = await aiorequests.get_img(url=weapon_url.format(data["武器"]["图标"]), size=(150, 150), save_path=weapon_icon)
talent_icon = talent_icon.convert('RGBA')

或者直接打包一个 get_img_rgba 方法,自动修改图片格式

CMHopeSunshine commented 2 years ago

已经修改

Sclock commented 2 years ago

真的吗,刚刚测试还是不行

CMHopeSunshine commented 2 years ago

是哪个指令, wiki的我改了

Sclock commented 2 years ago

定位在钟离命之座的 3,5 的图标

https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_01.png
https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_02.png

draw_role_card 方法内 await aiorequests.get_img 获取之后 mode 为p ,无法与 mode 为 RGBA 的底图叠加。

调试信息: ··· name UI_Talent_S_Zhongli_01 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_S_Zhongli_01.png talent_icon (45, 45) bg (1080, 1920) (529, 813) talent_icon: <PIL.Image.Image image mode=RGBA size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340>

name UI_Talent_S_Zhongli_02 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_S_Zhongli_02.png talent_icon (45, 45) bg (1080, 1920) (613, 813) talent_icon: <PIL.Image.Image image mode=RGBA size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340>

name UI_Talent_U_Zhongli_01 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_01.png talent_icon (45, 45) bg (1080, 1920) (697, 813) talent_icon: <PIL.Image.Image image mode=P size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340>

name UI_Talent_S_Zhongli_03 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_S_Zhongli_03.png talent_icon (45, 45) bg (1080, 1920) (781, 813) talent_icon: <PIL.Image.Image image mode=RGBA size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340>

name UI_Talent_U_Zhongli_02 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_U_Zhongli_02.png talent_icon (45, 45) bg (1080, 1920) (865, 813) talent_icon: <PIL.Image.Image image mode=P size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340>

name UI_Talent_S_Zhongli_04 url https://upload-bbs.mihoyo.com/game_record/genshin/constellation_icon/UI_Talent_S_Zhongli_04.png talent_icon (45, 45) bg (1080, 1920) (949, 813) talent_icon: <PIL.Image.Image image mode=RGBA size=45x45 at 0x19425C4D720> bg: <PIL.Image.Image image mode=RGBA size=1080x1920 at 0x19425AC3340> ···

CMHopeSunshine commented 2 years ago

我刚刚试了把这俩图片删了,再用ysd,能正常下载图片,draw_role_card.py文件的第116和117行

116        talent_icon = await aiorequests.get_img(url=talent_url.format(talent["图标"]), size=(45, 45),
117                                                save_path=talent_icon, mode='RGBA')

已经强制对下载的图片进行RGBA转换了

Sclock commented 2 years ago

好的 #143b1a3 修复了,但是没写出来,我以为没修。 重新pull了一下没问题了