use convert in script to create piclture abels with a space

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
qsecofer
Posts: 3
Joined: 2011-09-06T06:21:42-07:00
Authentication code: 8675308

use convert in script to create piclture abels with a space

Post by qsecofer »

I using convert in a shell (bash) script to create picture labels
the command I use in the script is

convert -background white -fill black -font DejaVu-Sans-Book -size 415x47 label:$NAME ./Images/NAME.jpg

If $NAME contains "Boer" then the line works correct.
If $NAME contains " Christabell Sunday" i get the following error messages

convert: unable to open image `Sunday': @ error/blob.c/OpenBlob/2498.
convert: no decode delegate for this image format `Sunday' @ error/constitute.c/ReadImage/532.

So I guess the question is how do I in a script generate a label texst from a variable with space's in it.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: use convert in script to create piclture abels with a sp

Post by magick »

Add quotes around the label: command line argument.
qsecofer
Posts: 3
Joined: 2011-09-06T06:21:42-07:00
Authentication code: 8675308

Re: use convert in script to create piclture abels with a sp

Post by qsecofer »

Magick thanks for you quick responce.

I have tried

convert -background white -fill black -font DejaVu-Sans-Book -size 415x47 label:"$NAME" ./Images/NAME.jpg
and

convert -background white -fill black -font DejaVu-Sans-Book -size 415x47 label:'$NAME' ./Images/NAME.jpg

but both give me the same error message.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: use convert in script to create piclture abels with a sp

Post by fmw42 »

what version of IM are you using and what platform? have you tried the command in command line mode outside your script? the double quotes should work fine. Single quotes won't resolve the variable. did you put quotes in your variable definition? NAME="Christabell Sunday"

This works perfectly fine for me on IM 6.7.2.2 Q16 Mac OSX Tiger.


NAME="Christabell Sunday"
convert -background white -fill black -font Arial -size 415x47 label:"$NAME" tmp1.png

Though the text is left justified. So you might want to add -gravity center. Or just specify only a width or only a height and let label: make the image just fill the text.
qsecofer
Posts: 3
Joined: 2011-09-06T06:21:42-07:00
Authentication code: 8675308

Re: use convert in script to create piclture abels with a sp

Post by qsecofer »

shame on me.

I had the $NAME at two places in the script and only changed 1 to have the quotes.

Problem solved thx
Post Reply