我在Mac 10.9.2上使用支持Magick ++的静态库编写了ImageMagick-6.8.8。
现在我尝试从第19页的Magick ++教程pdf执行以下示例(我已从以下代码中删除了注释
DrawableText::DrawableText(double x, double y, const string& text_to_write)
Image my_image(Geometry(320,220), Color("white"));
list<Drawable> text_draw_list;
text_draw_list.push_back(DrawableFont("-misc-fixed-medium-o-semicondensed—13-*-*-*-c-60-iso8859-1"));
text_draw_list.push_back(DrawableText(101, 50, "text to write on the canvas"));
text_draw_list.push_back(DrawableStrokeColor(Color("black")));
text_draw_list.push_back(DrawableFillColor(Color(0, 0, 0, MaxRGB)));
my_image.draw(text_draw_list);
我收到以下错误:
Magick: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3193
你能帮我搞清楚吗?
另外我不能使用注释,因为我没有在我的库中编译X支持,我相信使用注释需要X ...
以下是我的configure命令
的输出 Option Value
-------------------------------------------------------------------------------
Shared libraries --enable-shared=no no
Static libraries --enable-static=yes yes
Module support --with-modules=no no
GNU ld --with-gnu-ld=no no
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=no no
Install documentation: yes
Delegate Configuration:
BZLIB --with-bzlib=yes yes
Autotrace --with-autotrace=no no
Dejavu fonts --with-dejavu-font-dir=default none
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FFTW --with-fftw=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=yes no
FreeType --with-freetype=yes no
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (unknown)
Ghostscript fonts --with-gs-font-dir=default none
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=no
JBIG --with-jbig=yes no (failed tests)
JPEG v1 --with-jpeg=yes yes
JPEG-2000 --with-jp2=
LCMS v1 --with-lcms=yes no
LCMS v2 --with-lcms2=yes no
LQR --with-lqr=yes no
LTDL --with-ltdl=yes no
LZMA --with-lzma=yes yes
Magick++ --with-magick-plus-plus=yes yes
MUPDF --with-mupdf=no no
OpenEXR --with-openexr=yes no
OpenJP2 --with-openjp2=yes no
PANGO --with-pango=yes no
PERL --with-perl=no no
PNG --with-png=yes yes
RSVG --with-rsvg=no no
TIFF --with-tiff=yes yes
WEBP --with-webp=yes no
Windows fonts --with-windows-font-dir= none
WMF --with-wmf=no no
X11 --with-x=no no
XML --with-xml=yes yes
ZLIB --with-zlib=yes yes
X11 Configuration:
X_CFLAGS =
X_PRE_LIBS =
X_LIBS =
X_EXTRA_LIBS =
Options used to compile and link:
PREFIX = /Users/awais/Downloads/Image_Magick/IMagick/im
EXEC-PREFIX = /Users/awais/Downloads/Image_Magick/IMagick/im
VERSION = 6.8.8
CC = clang
CFLAGS = -arch x86_64 -Wall -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CPPFLAGS = -I/Users/awais/Downloads/Image_Magick/IMagick/im/include/ImageMagick-6
PCFLAGS = -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
DEFS = -DHAVE_CONFIG_H
LDFLAGS = -L/Users/awais/Downloads/Image_Magick/IMagick/im/tmp/lib -arch x86_64 -L/Users/awais/Downloads/Image_Magick/IMagick/ImageMagick-6.8.8-10/magick -L/Users/awais/Downloads/Image_Magick/IMagick/ImageMagick-6.8.8-10/wand -L/opt/local/lib
MAGICK_LDFLAGS = -L/Users/awais/Downloads/Image_Magick/IMagick/im/lib -L/Users/awais/Downloads/Image_Magick/IMagick/im/tmp/lib -arch x86_64 -L/Users/awais/Downloads/Image_Magick/IMagick/ImageMagick-6.8.8-10/magick -L/Users/awais/Downloads/Image_Magick/IMagick/ImageMagick-6.8.8-10/wand -L/opt/local/lib
LIBS = -ltiff -ljpeg -lpng16 -L/opt/local/lib -llzma -lbz2 -lxml2 -lz -lm
CXX = clang
CXXFLAGS = -arch x86_64 -D_THREAD_SAFE -pthread
FEATURES = DPC
DELEGATES = bzlib mpeg jng jpeg lzma png tiff xml zlib
答案 0 :(得分:2)
通过安装FontConfig,FreeType&amp;节省了很多麻烦。 Ghostscript。您可能已将X11放在系统/opt
目录中。如果没有,请跳至XQuartz并运行 .dmg 安装。 DejaVu&amp; Window的字体很好用,但不需要。安装字体库后,您需要重新配置ImageMagick(记住make clean
),然后重新安装。
对于 Magick ++ 教程,以下行有点令人困惑,因为它涉及一些您可能不熟悉的通配符。
DrawableFont("-misc-fixed-medium-o-semicondensed—13-*-*-*-c-60-iso8859-1")
从API开始,直接初始化字体可能是更好的介绍。
Magick::DrawableFont::DrawableFont ( const std::string & family_,
Magick::StyleType style_,
const unsigned int weight_,
Magick::StretchType stretch_
)
通过运行identify -list font
Font: Helvetica-Narrow
family: Helvetica Narrow
style: Normal
stretch: Condensed
weight: 400
glyphs: /usr/local/share/ghostscript/fonts/n019043l.pfb
然后只需应用正确的参数
DrawableFont font = DrawableFont("Helvetica Narrow",
NormalStyle,
400,
SemiCondensedStretch
);
text_draw_list.push_back(font);
text_draw_list.push_back(DrawableText(101, 50, "text to write on the canvas"));
text_draw_list.push_back(DrawableStrokeColor(Color("black")));
text_draw_list.push_back(DrawableFillColor(Color(0, 0, 0, MaxRGB)));
my_image.draw(text_draw_list);