ImageMagick provides the following command as an example of how to draw text on an image:
convert -size 250x50 xc:none -box white -pointsize 20 -gravity center \
-draw 'text 0,0 " '\'' \" $ \\ " ' \
-trim +repage text_special_sd.gif
When I run this code, I get this error:
convert: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3192.
The command I actually want to run is the following, but it gives the same error:
convert /tmp/tmpGRaZKy -fill none -stroke chartreuse -strokewidth 2 \
-draw "rectangle 221,155,256,191" -pointsize 17 -fill chartreuse \
-draw "text 20%,20% 'Score:0.84'" /Users/rose/home/video-object-detection/data/imagenet/n07840804/annotated/lbzhyvH74w8_10000/10000_99.jpg
The suggestions in this SO post did not fix the problem.
I'm on Mac. The answers I find on the web generally recommend trying a different combination of single and double quotes around the statement after -draw, but I think I've tried 'em all.
Here's the output of convert -version
:
Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib freetype jng jpeg ltdl lzma png xml zlib
Here's the output of convert -list configure
:
Path: /usr/local/Cellar/imagemagick/6.8.9-7/lib/ImageMagick//config-Q16/configure.xml
Name Value
-------------------------------------------------------------------------------
CC clang
CFLAGS -I/usr/local/Cellar/freetype/2.5.3_1/include/freetype2 -g -O2 -Wall -march=core2 -fexceptions -D_FORTIFY_SOURCE=0 -D_THREAD_SAFE -pthread -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
CODER_PATH /usr/local/Cellar/imagemagick/6.8.9-7/lib/ImageMagick/modules-Q16/coders
CONFIGURE ./configure '--disable-osx-universal-binary' '--prefix=/usr/local/Cellar/imagemagick/6.8.9-7' '--disable-dependency-tracking' '--enable-shared' '--disable-static' '--without-pango' '--with-modules' '--disable-openmp' '--without-gslib' '--without-perl' '--with-gs-font-dir=/usr/local/share/ghostscript/fonts' '--without-openjp2' '--without-x' '--with-freetype=yes' 'CC=clang' 'CXX=clang++'
CONFIGURE_PATH /usr/local/Cellar/imagemagick/6.8.9-7/etc/ImageMagick-6/
COPYRIGHT Copyright (C) 1999-2014 ImageMagick Studio LLC
CPPFLAGS -I/usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6
CXX clang++
CXXFLAGS -g -O2 -D_THREAD_SAFE -pthread
DEFS -DHAVE_CONFIG_H
DELEGATES bzlib mpeg freetype jng jpeg lzma png xml zlib
DISTCHECK_CONFIG_FLAGS 'CC=clang' 'CXX=clang++' --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-gslib=no --with-fontpath= --with-gs-font-dir=/usr/local/share/ghostscript/fonts --with-gvc=no --with-openjp2=no --with-pango=no --with-rsvg=no --with-wmf=no --with-perl=no
DOCUMENTATION_PATH /usr/local/Cellar/imagemagick/6.8.9-7/share/doc/ImageMagick-6
EXEC-PREFIX /usr/local/Cellar/imagemagick/6.8.9-7
EXECUTABLE_PATH /usr/local/Cellar/imagemagick/6.8.9-7/bin
FEATURES DPC Modules
FILTER_PATH /usr/local/Cellar/imagemagick/6.8.9-7/lib/ImageMagick/modules-Q16/filters
HOST x86_64-apple-darwin13.3.0
INCLUDE_PATH /usr/local/Cellar/imagemagick/6.8.9-7/include/ImageMagick-6
LDFLAGS -L/usr/local/Cellar/imagemagick/6.8.9-7/lib -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
LIB_VERSION 0x689
LIB_VERSION_NUMBER 6,8,9,7
LIBRARY_PATH /usr/local/Cellar/imagemagick/6.8.9-7/lib/ImageMagick
LIBS -L/usr/local/Cellar/freetype/2.5.3_1/lib -lfreetype -L/usr/local/Cellar/xz/5.0.5/lib -llzma -lbz2 -lz -lltdl -lm
NAME ImageMagick
PCFLAGS -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
PREFIX /usr/local/Cellar/imagemagick/6.8.9-7
QuantumDepth 16
RELEASE_DATE 2014-08-31
SHARE_PATH /usr/local/Cellar/imagemagick/6.8.9-7/share/ImageMagick-6
SHAREARCH_PATH /usr/local/Cellar/imagemagick/6.8.9-7/lib/ImageMagick/config-Q16
SVN_REVISION 16331
TARGET_CPU x86_64
TARGET_OS darwin13.3.0
TARGET_VENDOR apple
VERSION 6.8.9
WEBSITE http://www.imagemagick.org
Path: [built-in]
Name Value
-------------------------------------------------------------------------------
FEATURES
NAME ImageMagick
QuantumDepth 16
UPDATE
~ convert \
> -debug draw \
> -size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
prints:
2014-12-06T14:52:40-08:00 0:00.150 0.010u 6.8.9 Draw convert[39332]: draw.c/DrawImage/1784/Draw
begin draw-image
2014-12-06T14:52:40-08:00 0:00.160 0.010u 6.8.9 Draw convert[39332]: draw.c/DrawImage/3129/Draw
text 0,0 "A B C"
2014-12-06T14:52:40-08:00 0:00.160 0.010u 6.8.9 Draw convert[39332]: draw.c/DrawPrimitive/4221/Draw
begin draw-primitive
2014-12-06T14:52:40-08:00 0:00.160 0.010u 6.8.9 Draw convert[39332]: draw.c/DrawPrimitive/4223/Draw
affine: 1 0 0 1 0 0
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
2014-12-06T14:52:40-08:00 0:00.310 0.040u 6.8.9 Draw convert[39332]: draw.c/DrawPrimitive/4639/Draw
end draw-primitive
2014-12-06T14:52:40-08:00 0:00.310 0.040u 6.8.9 Draw convert[39332]: draw.c/DrawImage/3179/Draw
end draw-image
convert: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3192.
An interesting part of this command:
convert -debug all -size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
is this:
2014-12-06T14:57:36-08:00 0:00.100 0.030u 6.8.9 Annotate convert[39441]: annotate.c/GetTypeMetrics/798/Annotate
Metrics: text: A B C; width: 0; height: 0; ascent: 0; descent: 0; max advance: 0; bounds: 0,0 0,0; origin: 0,0; pixels per em: 0,0; underline position: 0; underline thickness: 0
2014-12-06T14:57:36-08:00 0:00.110 0.040u 6.8.9 Exception convert[39441]: annotate.c/RenderFreetype/1127/Exception
unable to read font `(null)'
2014-12-06T14:57:36-08:00 0:00.110 0.040u 6.8.9 Annotate convert[39441]: annotate.c/RenderPostscript/1649/Annotate
Font none; pointsize 12
The end of the output of that command is this:
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11175/Coder
Wrote PNG image data
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11178/Coder
Width: 50
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11181/Coder
Height: 50
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11190/Coder
PNG bit-depth written: 1
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11199/Coder
PNG color-type written: 0
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11202/Coder
PNG Interlace method: 0
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11263/Coder
Setting up text chunk
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11266/Coder
keyword: 'date:create'
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11263/Coder
Setting up text chunk
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11266/Coder
keyword: 'date:modify'
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11282/Coder
Writing PNG end info
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Resource convert[39441]: resource.c/RelinquishMagickResource/862/Resource
Memory: 50B/24.4KiB/2GiB
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WriteOnePNGImage/11344/Coder
exit WriteOnePNGImage()
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Coder convert[39441]: png.c/WritePNGImage/12183/Coder
exit WritePNGImage()
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Cache convert[39441]: cache.c/DestroyPixelCache/965/Cache
destroy 1.png[0]
2014-12-06T14:57:36-08:00 0:00.170 0.060u 6.8.9 Resource convert[39441]: resource.c/RelinquishMagickResource/862/Resource
Memory: 25KB/0B/2GiB
convert: non-conforming drawing primitive definition `text' @ error/draw.c/DrawImage/3192.
This annotate command,
~ convert \
> -size 50x50 xc:none -gravity center -annotate +0+0 "A B C" 2.png
Gave this output:
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
The png created is 257 bytes, and it's 50x50 pixels, but I don't see any letters. In Preview, it looks completely transparent.
To debug this problem, I'd start to first use a more simple command:
convert \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
Probably this doesn't work either. Then add -verbose
to the command:
convert \
-verbose \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
Maybe you now get a better clue about what goes wrong? If not, add -debug draw
:
convert \
-debug draw \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
Inspect all messages. There may be many dozen of them. Any clue? If not, try -debug all
:
convert \
-debug all \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
If this does not yield any hints, there is an alternative image operator to try in place of -draw
: -annotate
. Here is the (almost) equivalent command:
convert \
-size 50x50 xc:none -gravity center -annotate +0+0 "A B C" 2.png
Does -annotate
work?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With