Page 1 of 1

convert -draw text fails if the text starts with a digit

Posted: 2008-03-23T09:36:38-07:00
by naoliv
Hi!

From http://bugs.debian.org/344801:
This silently fails (in that it does not draw any text on the image, even though it produces bar.jpg):

Code: Select all

convert -gravity southwest -font helvetica -undercolor yellow -fill black -pointsize 24 -draw 'text 1,1 334sadadsafjlajfajslfdjalsjfd' foo.jpg bar.jpg
While this works as expected:

Code: Select all

convert -gravity southwest -font helvetica -undercolor yellow -fill black -pointsize 24 -draw 'text 1,1 x334sadadsafjlajfajslfdjalsjfd' foo.jpg bar.jpg
I can reproduce it with 6.4.0-0 beta (it gives "convert: Non-conforming drawing primitive definition `text'." if using a number as the first char of the string).

Thank you!

Re: convert -draw text fails if the text starts with a digit

Posted: 2008-03-23T09:50:29-07:00
by naoliv
Hi again!

Maybe related (http://bugs.debian.org/399060):

Code: Select all

touch 1.gif
convert -size 200x200 -fill blue -draw 'circle 50,50 0,50' 1.gif 1.gif
Now, we want two circles:

Code: Select all

convert -draw 'image Over 100,100 200,200 1.gif' 1.gif 2.gif
convert: Non-conforming drawing primitive definition `image'.
This is a bug! There is a workaround: try a different filename.

Code: Select all

cp 1.gif a.gif
convert -draw 'image Over 100,100 200,200 a.gif' a.gif 2.gif
Thank you!

Re: convert -draw text fails if the text starts with a digit

Posted: 2008-03-23T16:34:37-07:00
by magick
Instead of
  • -draw 'text 1,1 334sadadsafjlajfajslfdjalsjfd'
use
  • -draw 'text 1,1 "334sadadsafjlajfajslfdjalsjfd"'
Instead of
  • convert -draw 'image Over 100,100 200,200 1.gif' 1.gif 2.gif
use
  • convert -draw 'image Over 100,100 200,200 "1.gif"' 1.gif 2.gif

Re: convert -draw text fails if the text starts with a digit

Posted: 2013-05-20T07:47:51-07:00
by ronald
I want to print the file name of an image on the image. When the file name begins with a number -draw text fails. Below is how to do that out of a BASH shell script with parameterization.

The key is to make a new environment variable with quotes

Ron

Code: Select all


#!/bin/bash
# this works
convert -fill white -pointsize 240 -draw 'text 100,36064 "33MT21_130402"' -pointsize 96 -draw 'text 5926,36114 "Phenotype_Screening_Corporation"' ../stereo/33MT21_130402_n.png ../stereo/33MT21_130402.png

export NAMECOL=100
export NAMEROW=36064
export BASEFILE="33MT21_130402"
export INSTCOL=5926
export INSTROW=36114
# note that quotes are put around the environment variable BASEFILE
export IMGBASEFILE="\"${BASEFILE}\""
export INSTITUTION="Phenotype_Screening_Corporation"

echo ${NAMECOL}
echo ${NAMEROW}
echo ${BASEFILE}
echo ${INSTCOL}
echo ${INSTROW}
echo ${IMGBASEFILE}
echo ${INSTITUTION}

# this does not work
convert -fill white -pointsize 240 -draw 'text "${NAMECOL},${NAMEROW}" \
  "\"${BASEFILE}\""' -pointsize 96 -draw "text "${INSTCOL},${INSTROW}" \
   "${INSTITUTION}"" ../stereo/${BASEFILE}_n.png ../stereo/${BASEFILE}.png 

# this works note use of IMGBASEFILE
convert -fill white -pointsize 240 -draw "text "${NAMECOL},${NAMEROW}" \
  "${IMGBASEFILE}"" -pointsize 96 -draw "text "${INSTCOL},${INSTROW}" \
   "${INSTITUTION}"" ../stereo/${BASEFILE}_n.png ../stereo/${BASEFILE}.png 


Re: convert -draw text fails if the text starts with a digit

Posted: 2013-05-21T22:38:11-07:00
by anthony
The draw "MSVG" language sytax requires the quotes (double or single) around the text or the image filename.

The fact that it can draw text without the quotes is more likely the bug, rather than the other way around!!!!


For escaping those quotes and other spacial characters see
IM Examples, Drawing on Images, Drawing Special Characters in the Text String
http://www.imagemagick.org/Usage/draw/#text

Note this is why it is often easier to use annotate, though then you have to deal with 'percent escapes'. Unless you get annotate to read the string from a file or stream (which is literial or as-is)

See IM examples, Text to Image Handling, Special Escape Characters in Text Arguments
http://www.imagemagick.org/Usage/text/#escape_chars