【问题标题】:Magick++: Image -> draw() problems when drawing textMagick ++:图像 - >绘制文本时的问题
【发布时间】:2014-05-22 14:49:45
【问题描述】:

我在 Mac 10.9.2 上使用支持 Magick++ 的静态库编译了 ImageMagick-6.8.8。

现在我正在尝试执行第 19 页的 Magick++ 教程 pdf 中的以下示例(我已从以下代码中删除了 cmets

    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

你能帮我解决这个问题吗?

我也不能使用 annotate,因为我没有在我的库中编译 X 支持,我相信使用 annotate 需要 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

【问题讨论】:

    标签: imagemagick magick++ magickwand


    【解决方案1】:

    安装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);
    

    【讨论】:

    • 感谢您的快速建议。我正在考虑使用 ImageMagick 编译 FreeType 委托,而不是将其安装为共享库。同样对于 X11,我确实在我的系统上安装了 XQuatrz,但我想使用静态库,以便我的应用程序不依赖任何第三方并内置所有内容。请让我知道我是否还应该为 FontConfig & 添加委托GhostScript 也是如此。
    • 我在尝试命令行后实际上确定了对 FreeType 的要求(发布此问题后)./convert IMG_0001.JPG -resize 10% -draw "text 25,60 'Magick'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta 1.JPG 它给了我以下错误convert: delegate library support not built-in 'none' (Freetype) @ warning/annotate.c/RenderFreetype/1537. convert: Postscript delegate failed '/var/tmp/magick-3247Mg-ixYma8Adp': No such file or directory @ error/ps.c/ReadPSImage/840.
    • 基于上述建议,以下对我有用:brew install ghostscript
    猜你喜欢
    • 2020-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 2013-06-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-24
    相关资源
    最近更新 更多