Error with using Imagemagick convert from a shell script

Error with using Imagemagick convert from a shell script

am 03.10.2007 08:14:20 von samir

Hello,
I have the following part in a shell script.

export TextToPrint="Does this print"
textString=`echo "'text 100,250 \"$TextToPrint\"'"`
echo $textString
echo convert -font helvetica -fill black -pointsize 36 -draw
$textString temp1/$filename temp1/$filename.new.jpg
convert -font helvetica -fill black -pointsize 36 -draw $textString
temp1/$filename temp1/$filename.new.jpg

Output
-----------
'text 100,250 "Does this print"'
convert -font helvetica -fill black -pointsize 36 -draw 'text 100,250
"Does this print"' temp1/000.jpg temp1/000.jpg.new.jpg
convert: Non-conforming drawing primitive definition `text'.

....
surprisingly,
if I copy the echoed convert command from this output and paste it
onto the shell prompt and execute it independently ...it works !!
but, it does not seem to work from the shell script...

any idea/help on this would be greatly appreciated..
samir

Re: Error with using Imagemagick convert from a shell script

am 03.10.2007 11:11:04 von Pierre Gaston

Samir wrote:
> Hello,
> I have the following part in a shell script.
>
> export TextToPrint="Does this print"
> textString=`echo "'text 100,250 \"$TextToPrint\"'"`
....
> surprisingly,
> if I copy the echoed convert command from this output and paste it
> onto the shell prompt and execute it independently ...it works !!
> but, it does not seem to work from the shell script...

The problem is that when you run

command "foo bar"

the quotes are removed before what is inside is being passed as
an argument to command. When you do:

a='"foo bar" baz'
command $a

The quotes are quoted and sees to mean something special for the
shell. Moreover as $a is not quoted the shell will perform word
splitting and create three arguments
"foo, bar" and baz. (with the quotes inside)

A workaround with bash is to use an array:

a=("foo bar" baz)
command "${a[@]}"

hope this helps.

--
pgas@sdf.lonestar.org
SDF Public Access UNIX System - http://sdf.lonestar.org

Re: Error with using Imagemagick convert from a shell script

am 03.10.2007 13:55:05 von Volker Strell

Samir wrote:
> Hello,
> I have the following part in a shell script.
>
> export TextToPrint="Does this print"
> textString=`echo "'text 100,250 \"$TextToPrint\"'"`
> echo $textString
> echo convert -font helvetica -fill black -pointsize 36 -draw
> $textString temp1/$filename temp1/$filename.new.jpg
> convert -font helvetica -fill black -pointsize 36 -draw $textString
> temp1/$filename temp1/$filename.new.jpg
>
> Output
> -----------
> 'text 100,250 "Does this print"'
> convert -font helvetica -fill black -pointsize 36 -draw 'text 100,250
> "Does this print"' temp1/000.jpg temp1/000.jpg.new.jpg
> convert: Non-conforming drawing primitive definition `text'.
>
> ...
> surprisingly,
> if I copy the echoed convert command from this output and paste it
> onto the shell prompt and execute it independently ...it works !!
> but, it does not seem to work from the shell script...
>
> any idea/help on this would be greatly appreciated..
> samir
>
It's a quoting issue. You have to remove the single quotes from the
textString definition. Otherwise they will become part of the draw
command which is not what you want. When you call convert you must put
$textString in doublequotes to prevent word splitting. This should work:

textString=`echo "text 100,250 \"$TextToPrint\""`
convert ... -draw "$textString" ...