手上有otf和ttf格式的字体,但是需要将其放到网站中使用,那就要转换城woff2格式来减小体积,所以找到了一些工具,在这里记录一下

一、ttf2woff2(ttf转woff2)

开源地址:https://github.com/nfroidure/ttf2woff2

这是一个NodeJS包,需要提前准备好NodeJS环境

  1. 安装:npm i ttf2woff2 -g

  2. 使用

    Linux:cat xxx.ttf | ttf2woff2 > xxx.woff2

    Windows(PowerShell中):Start-Process -NoNewWindow -Wait ttf2woff2.cmd -RedirectStandardInput font.ttf -RedirectStandardOutput font.woff2或者start-process -nnw -wait ttf2woff2.cmd -rsi font.ttf -rso font.woff2

转换时间稍长,需要耐心等待

也可通过调用API来使用,详情参考软件文档

二、otf2ttf(otf转ttf)

开源地址:https://github.com/awesometoolbox/otf2ttf

这是一个Python包,需要提前准备好Python环境

  1. 安装:pip install otf2ttf
  2. 使用:otf2ttf xxx.ttf

三、其他工具

1.woff2

https://github.com/google/woff2

谷歌出品,C++编写,可以实现ttf和woff2互转

2.woff2otf

https://github.com/hanikesn/woff2otf

Python编写,可以实现woff转otf

还有其他工具的话,后期再来更新