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

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

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

Post 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!
naoliv
Posts: 110
Joined: 2007-12-10T18:54:27-07:00
Location: Brazil

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

Post 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!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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
ronald
Posts: 1
Joined: 2013-05-20T07:28:03-07:00
Authentication code: 6789

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

Post 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 

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply