Coder Social home page Coder Social logo

dynrender-skia's Introduction

DynRender-skia

使用skia渲染BiliBili动态 更新页面效果的优先级会很低

注意

Linux用户在导入skia-python包时可能会遇到以下报错

libGL.so.1: cannot open shared object file: No such file or directory

Windows用户在缺少Microsoft Visual C++ Runtime时可能会遇到以下报错

ImportError: DLL load failed while importing skia: The specified module could not be found.

解决方法

ubuntu用户

apt install libgl1-mesa-glx

ArchLinux用户

pacman -S libgl

centos用户

yum install mesa-libGL -y

Windows用户

下载链接Microsoft Visual C++ 2015 Redistributable Update 3 RC

使用方法

安装必要依赖

pip install dynamicadaptor dynrender-skia

测试

import httpx
import asyncio
import skia
from dynrender_skia.Core import DynRender
from dynamicadaptor.DynamicConversion import formate_message


# 现在风控升级,大概率请求失败,建议携带cookie进行请求
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"
    }

    # 发起HTTP请求并解析JSON响应
    message_json = httpx.get(url, headers=headers).json()

    # 格式化消息数据
    message_formate = await formate_message("web", message_json["data"]["item"])

    # 使用DynRender执行动态渲染
    img = await DynRender().run(message_formate)

    # 将渲染后的图像转换为Skia Image对象
    img = skia.Image.fromarray(img, colorType=skia.ColorType.kRGBA_8888_ColorType)

    # 保存图像为PNG文件
    img.save("1.png")


# 当文件作为主程序执行时
if __name__ == "__main__":
    asyncio.run(web_test())

效果展示

示例图片

dynrender-skia's People

Contributors

balconyjh avatar dependabot[bot] avatar polyisoprene avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

dynrender-skia's Issues

附加卡片文字渲染异常

大佬,请问调用库之后生成的图片其他地方字体正常,但附加卡片的 ‘预约’ 两字是方块,是我哪里做得不对吗?能请教下该怎么解决吗?
用的版本是git拉取的当前最新代码

图片

动态id:822504963263430656

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.