puppeteer使用截图功能出现乱码

转自:https://www.jianshu.com/p/f2ba4f5b8f36

一般的linux机器是没有中文字库的,解决方案就是对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

 

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

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值