1

我在 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...

这是我的配置命令的输出

                  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
4

1 回答 1

2

安装FontConfigFreeTypeGhostscript会省去很多麻烦。/opt您可能已经在系统目录中安装了 X11 。如果没有,跳转到XQuartz并运行.dmg安装。DejaVu & 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);

要在画布上书写的示例文本

于 2014-04-09T13:50:04.400 回答