美文网首页
puppeteer截图乱码

puppeteer截图乱码

作者: Alinawu | 来源:发表于2019-06-28 16:58 被阅读0次

最近使用puppeteer来写一个M页的监控工具,部署到linux上运行后发现截图中文乱码了:


搜了一些资料,解决方法如下:
一、安装fontconfig
yum -y install fontconfig
这个命令执行完成之后,就可以在/usr/share文件夹里面看到fonts和fontconfig

二、添加中文字体库
从window的C:\Windows\Fonts里面把你需要的字体拷贝出来。比如simfang.ttf
在CentOS的/usr/share/fonts新建一个叫chinese的文件夹
然后把刚刚拷贝字体放到CentOS的/usr/share/fonts/chinese里面
修改chinese目录的权限:
chmod -R 775 /usr/share/fonts/chinese

接下来需要安装ttmkfdir来搜索目录中所有的字体信息,并汇总生成fonts.scale文件,输入命令
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir

修改字体配置文件 vi /etc/fonts/fonts.conf

<!-- Font directory list -->

        <dir>/usr/share/fonts</dir>
        <dir>/usr/share/X11/fonts/Type1</dir>
        <dir>/usr/share/X11/fonts/TTF</dir>
        <dir>/usr/local/share/fonts</dir>
        <dir>/usr/local/share/fonts/chinese</dir>
        <dir prefix="xdg">fonts</dir>
        <!-- the following element will be removed in the future -->
        <dir>~/.fonts</dir>

刷新内存中的字体缓存,fc-cache
看一下现在机器上已经有了刚才添加的字体。fc-list :lang=zh

现在再运行一下截图,就没问题啦~


相关文章

网友评论

      本文标题:puppeteer截图乱码

      本文链接:https://www.haomeiwen.com/subject/ymsecctx.html