Question

I complied ImageMagick-6.8.8 on Mac 10.9.2 with static libraries with support for Magick++.

Now I am trying to execute the following example from the Magick++ tutorial pdf on page 19 ( I have removed the comments from the following code

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

I get the following error:

Magick: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3193

Can you help me figure this out.

Also I cannot use annotate as I have not compiled X support in my libraries and I believe that using annotate requires X...

Here is the output from my configure command

                  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
Was it helpful?

Solution

It'll save a lot of trouble by installing FontConfig, FreeType & Ghostscript. You probably already have X11 sitting in your systems /opt directory. If not, jump over to XQuartz and run the .dmg install. DejaVu & Window's fonts are nice to have, but not needed. After installing the font libraries, you'll need to re-configure ImageMagick (remember to make clean), and re-install.

For the Magick++ tutorial, the following line is a bit confusing, as it involves a few wildcards that you may not be familiar with.

DrawableFont("-misc-fixed-medium-o-semicondensed—13-*-*-*-c-60-iso8859-1")

From the API, it may be a better introduction to initialize a font directly.

Magick::DrawableFont::DrawableFont  ( const std::string & family_,
                                      Magick::StyleType   style_,
                                      const unsigned int  weight_,
                                      Magick::StretchType stretch_ 
                                    )

Find a typeface you wish to use by running identify -list font

Font: Helvetica-Narrow
  family: Helvetica Narrow
  style: Normal
  stretch: Condensed
  weight: 400
  glyphs: /usr/local/share/ghostscript/fonts/n019043l.pfb 

Then it's just a matter of applying the correct parameters

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

Example text to write on canvas

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top