ImageMagick提供以下命令作为如何在图像上绘制文本的示例:
convert -size 250x50 xc:none -box white -pointsize 20 -gravity center \
-draw 'text 0,0 " '\'' \" $ \\ " ' \
-trim +repage text_special_sd.gif
当我运行此代码时,我收到此错误:
转换:不符合图纸的原始定义`text' @ error / draw.c / DrawImage / 3192。
我实际想要运行的命令如下,但它给出了同样的错误:
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
此SO post中的建议无法解决问题。
我在Mac上。我在网上找到的答案通常建议在提取后的语句周围尝试不同的单引号和双引号组合,但我想我已经尝试了所有。
这是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
这是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
更新
~ convert \
> -debug draw \
> -size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
打印:
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.
此命令的一个有趣部分:
convert -debug all -size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
就是这样:
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
该命令输出的结尾是:
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.
这个注释命令,
~ convert \
> -size 50x50 xc:none -gravity center -annotate +0+0 "A B C" 2.png
给出了这个输出:
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
convert: unable to read font `(null)' @ error/annotate.c/RenderFreetype/1127.
创建的png是257个字节,它是50x50像素,但我没有看到任何字母。在预览中,它看起来完全透明。
答案 0 :(得分:0)
要调试此问题,我首先要开始使用更简单的命令:
convert \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
这可能也不起作用。然后将-verbose
添加到命令:
convert \
-verbose \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
也许你现在可以更好地了解出了什么问题?如果没有,请添加-debug draw
:
convert \
-debug draw \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
检查所有消息。可能有很多这样的。任何线索?如果没有,请尝试-debug all
:
convert \
-debug all \
-size 50x50 xc:none -gravity center -draw 'text 0,0 "A B C" ' 1.png
如果这不会产生任何提示,则可以使用替代图像运算符代替-draw
:-annotate
。这是(几乎)等效的命令:
convert \
-size 50x50 xc:none -gravity center -annotate +0+0 "A B C" 2.png
-annotate
是否有效?