使用skia-python将BiliBili动态渲染为图片
Project description
DynRender-skia
使用skia渲染BiliBili动态
注意
Linux用户在导入skia-python包时可能会遇到以下报错
libGL.so.1: cannot open shared object file: No such file or directory
解决方法
ubuntu用户
apt install libgl1-mesa-glx
ArchLinux用户
pacman -S libgl
centos用户
yum install mesa-libGL -y
使用方法
安装必要依赖
pip install dynamicadaptor dynrender-skia
测试
import httpx
import asyncio
import skia
from dynrender_skia.Core import DynRender
from dynamicadaptor.DynamicConversion import formate_message
async def web_test():
dyn_id = "440646043801479846"
url = f"https://api.bilibili.com/x/polymer/web-dynamic/v1/detail?timezone_offset=-480&id={dyn_id}&features=itemOpusStyle"
headers = {
"referer": f"https://t.bilibili.com/{dyn_id}",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
}
message_json = httpx.get(url, headers=headers).json()
message_formate = await formate_message("web", message_json["data"]["item"])
img = await DynRender().run(message_formate)
img = skia.Image.fromarray(img, colorType=skia.ColorType.kRGBA_8888_ColorType)
img.save("1.png")
if __name__ == "__main__":
asyncio.run(web_test())
效果展示
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dynrender_skia-0.1.8.tar.gz
(358.4 kB
view hashes)
Built Distribution
dynrender_skia-0.1.8-py3-none-any.whl
(362.2 kB
view hashes)
Close
Hashes for dynrender_skia-0.1.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe98c6b2ab736ca6d73158fdefa7ff3774c2bcf8215c16ec5dd5272e4623f4f3 |
|
MD5 | 0f10b604ed166d8171de90ded8d13ecd |
|
BLAKE2b-256 | 24d6704ca05f9348e248af227c3a441a7349c95755b3c3ada9ba9dbd0d73f48d |