在 FreeBSD 系统中安装 GraphicsMagick 的步骤并不复杂,但有几个常见陷阱需要提前留意。下面按流程逐步讲解:安装软件、查看编译参数、上传字体文件、最后配置字体路径。每一步都附上关键细节,帮你避免后续可能出现的错误。
1、安装 GraphicsMagick
直接使用 pkg 包管理器安装即可:
pkg install GraphicsMagick
2、查看编译参数
安装完成后不要急着调用,先执行 gm -version 命令,重点查看编译参数中 --with-windows-font-dir 后面的路径。这个路径决定了 GraphicsMagick 去哪里查找 Windows 字体。如果该路径在系统中不存在,记得手动用 mkdir 创建目录。
特别提醒:FreeBSD 10.3 版本之后默认字体路径有所调整,旧版本位于 /usr/local/lib/X11 下,新版本已迁移到 /usr/local/share 目录内,更符合常规结构,但也容易让人一时疏忽踩坑。
# gm -version GraphicsMagick 1.3.23 2015-11-07 Q16 https://www.GraphicsMagick.org/ Copyright (C) 2002-2015 GraphicsMagick Group. Additional copyrights and licenses apply to this software. See https://www.GraphicsMagick.org/www/Copyright.html for details. Feature Support: Native Thread Safe yes Large Files (> 32 bit) yes Large Memory (> 32 bit) yes BZIP yes DPS no FlashPix no FreeType yes Ghostscript (Library) no JBIG yes JPEG-2000 yes JPEG yes Little CMS yes Loadable Modules no OpenMP yes (201107) PNG yes TIFF yes TRIO no UMEM no WebP yes WMF yes X11 yes XML yes ZLIB yes Host type: amd64-portbld-freebsd10.1 Configured using the command: ./configure '--enable-shared' '--enable-static' '--with-windows-font-dir=/usr/local/share/fonts/webfonts' '--without-perl' '--without-dps' '--without-fpx' '--with-threads' '--enable-onmp' '--disable-openmp-slow' '--with-quantum-depth=16' '--with-webp' '--with-wmf' '--with-x' '--with-xml' '--x-libraries=/usr/local/lib' '--x-includes=/usr/local/include' '--prefix=/usr/cal' '--localstatedir=/var' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=amd64-portbld-freebsd10.1' 'build_alias=amd64-portbld-freebsd10.1' 'CC=gcc48' 'CFLAGS=-O2 -pip -isystem /usr/local/include -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -fno-strict-aliasing' 'LDFLAGS= -L/usr/local/lib -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -L/usr/lal/lib/gcc48' 'LIBS=' 'CPPFLAGS=-isystem /usr/local/include' 'CPP=cpp48' 'CXX=c++' 'CXXFLAGS=-O2 -pipe -isystem /usr/local/include -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -fno-rict-aliasing -isystem /usr/local/include -Wl,-rpath=/usr/local/lib/gcc48' Final Build Parameters: CC = gcc48 -std=gnu99 CFLAGS = -fopenmp -O2 -pipe -isystem /usr/local/include -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -fno-strict-aliasing -Wall -D_THREAD_SAFE CPPFLAGS = -isystem /usr/local/include -I/usr/local/include -I/usr/local/include/freetype2 -I/usr/local/include/libxml2 CXX = c++ CXXFLAGS = -O2 -pipe -isystem /usr/local/include -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -fno-strict-aliasing -isystem /usr/local/include -Wl,-rpath=/usr/local/lib/gcc48 -D_TEAD_SAFE LDFLAGS = -L/usr/local/lib -fstack-protector -Wl,-rpath=/usr/local/lib/gcc48 -L/usr/local/lib/gcc48 -L/usr/local/lib LIBS = -ljbig -lwebp -llcms2 -ltiff -lfreetype -ljasper -ljpeg -lpng16 -lwmflite -lXext -lX11 -llzma -lbz2 -lxml2 -lz -lm -lgomp -lpthread
3、上传中文字体
从你的 Windows 系统 C:\Windows\Fonts 目录中选取所需字体即可。建议至少上传两个字体文件:一个英文字体(例如 arial.ttf,虽然系统通常自带,但为保险可一并上传),以及一个中文字体(比如 simsun.ttf 或其他 sim 系列字体)。当然,你也可以根据项目需求多传几个。上传后务必放置到第二步查到的字体目录中。
4、编辑字体配置文件
切换到 GraphicsMagick 的字体配置目录:
cd /usr/local/lib/GraphicsMagick/config
编辑 type-windows.mgk 文件,在文件末尾添加新字体的配置信息。注意:arial 等英文字体通常已在默认配置中,因此只需添加上传的中文字体。每个字体文件需添加一小节配置,示例如下:
name="simli"
fullname="simli"
family="simli"
weight="400"
style="normal"
stretch="normal"
glyphs="/usr/local/share/fonts/webfonts/simli.ttf"
/>
其中 name、fullname、family 可保持一致,glyphs 填写该字体的实际路径。保存并退出,再次运行 GraphicsMagick 相关命令即可识别新添加的字体。
