puppeteer截圖亂碼

最近使用puppeteer來寫一個(gè)M頁的監(jiān)控工具,部署到linux上運(yùn)行后發(fā)現(xiàn)截圖中文亂碼了:


搜了一些資料,解決方法如下:
一、安裝fontconfig
yum -y install fontconfig
這個(gè)命令執(zhí)行完成之后,就可以在/usr/share文件夾里面看到fonts和fontconfig

二、添加中文字體庫(kù)
從window的C:\Windows\Fonts里面把你需要的字體拷貝出來。比如simfang.ttf
在CentOS的/usr/share/fonts新建一個(gè)叫chinese的文件夾
然后把剛剛拷貝字體放到CentOS的/usr/share/fonts/chinese里面
修改chinese目錄的權(quán)限:
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>

刷新內(nèi)存中的字體緩存,fc-cache
看一下現(xiàn)在機(jī)器上已經(jīng)有了剛才添加的字體。fc-list :lang=zh

現(xiàn)在再運(yùn)行一下截圖,就沒問題啦~


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容