解決的問題?
- 最近有一個需求是在 Linux 上使用 phantomjs 對指定網頁進行截圖后,把截圖發送到釘釘消息群。但是在過程中遇到了截圖無法正確顯示中文的問題,查詢各種資料都未解決。在快要走火入魔將要放棄的時候,突然背后傳來一個聲音“看看Linux的中文包裝沒有”。瞬間感覺世界都出現了一絲陽光,馬上在網上搜索了相關資料,覺得可能就是這個問題導致的,立馬按照網上的指導一頓操作,what fuck 竟然搞定了!
- 所以為了記錄這次的經歷,遂提筆寫下本篇文章以作記錄,感謝那名點拔我的高人。
葵花寶典
第一式:檢查系統是否有字體庫
- 查看字體庫列表
fc-list
- 如果沒有安裝字體庫,使用下面的命令安裝字體庫
yum -y install fontconfig
第二式:安裝中文字體
- 首先在/usr/shared/fonts 目錄下新建一個目錄 chinese。
mkdir /usr/shared/fonts/chinese
- 上傳字體文件到 chinese 文件夾中。
<!-- 悄悄的說:這2個文件可以在Windows系統的C:\fonts文件夾中找到. -->
simsun.ttc
simsunb.ttf
- 修改 chinese 目錄的權限
chmod -R 755 /usr/share/fonts/chinese
- 安裝 ttmkfdir 來搜索目錄中所有的字體信息,並匯總生成 fonts.scale 文件。
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
- 修改字體配置文件,添加 chinese 文件夾的地址
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>
<!-- 添加chinese文件夾的地址 -->
<dir>/usr/share/fonts/chinese</dir>
<dir prefix="xdg">fonts</dir>
<!-- the following element will be removed in the future -->
<dir>~/.fonts</dir>
- 清除字體緩存
fc-cache
OKOK,接下來就是見證奇跡的時刻了。
感謝無名前輩留下的經驗
- Linux CentOS 7 安裝字體庫 & 中文字體:https://www.linuxidc.com/Linux/2016-09/135548.htm
- centos系統怎么設置系統語言為中文:https://www.php.cn/centos/445626.html