[Bash] Passing data to ImageMagick's convert from bash

Programming languages, Coding, Executables, Package Creation, and Scripting.
Post Reply
Message
Author
morse_the_horse
Posts: 66
Joined: 2013-06-29 22:07

[Bash] Passing data to ImageMagick's convert from bash

#1 Post by morse_the_horse »

Imagemagik's convert command to create a png file from a text in Rev Version:
ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25https://imagemagick.org

which is part of the debian imagmagic version:
imagemagick is already the newest version (8:6.9.11.60+dfsg-1.3+deb11u1)
uses this form in its command line:

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
      -fill blue -size 300 label:'ASHEVILLE EAST (BACK) WALL' $RamDir/Loc$Count.png
which works. Note that the "label" must be of the form Label:text with no spaces or enclosed in single quotes as above
The output image file shows just the text without any quotes.

However If I have this:

Code: Select all

echo $LocationName|sed 's/\x22/\x27/g'
which produces this output:
'ASHEVILLE EAST (BACK) WALL'
and use that in the same command line above as:

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
-fill blue -size 300 label:$(echo $LocationName|sed 's/\x22/\x27/g') $RamDir/Loc$Count.png
I get garbage errors because convert sees the line without the beggining and ending single quotes and so thinks there are a bunch of
unknown input information

If I do this:

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
-fill blue -size 300 label:$LocationName $RamDir/Loc$Count.png
I get the same garbage
but this:

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
-fill blue -size 300 label:"$LocationName" $RamDir/Loc$Count.png
produces an image file with the quotes included.
Last edited by morse_the_horse on 2023-03-06 21:47, edited 1 time in total.

lindi
Posts: 100
Joined: 2022-07-12 14:10
Been thanked: 16 times

Re: [Bash] Passing data to ImageMagick's convert from bash

#2 Post by lindi »

How about

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
-fill blue -size 300 label :"$LocationName" $RamDir/Loc$Count.png

morse_the_horse
Posts: 66
Joined: 2013-06-29 22:07

Re: [Bash] Passing data to ImageMagick's convert from bash

#3 Post by morse_the_horse »

lindi wrote: 2023-03-05 22:01 How about

Code: Select all

convert -background LightBlue1 -border 10 -bordercolor red -font Helvetica-Bold \
-fill blue -size 300 label :"$LocationName" $RamDir/Loc$Count.png
convert requires that there be no space between the word label and the colon. Were you able to get that to work?

lindi
Posts: 100
Joined: 2022-07-12 14:10
Been thanked: 16 times

Re: [Bash] Passing data to ImageMagick's convert from bash

#4 Post by lindi »

In the first post you listed a command where there is a space and said that the command works?

morse_the_horse
Posts: 66
Joined: 2013-06-29 22:07

Re: [Bash] Passing data to ImageMagick's convert from bash

#5 Post by morse_the_horse »

lindi wrote: 2023-03-06 21:42 In the first post you listed a command where there is a space and said that the command works?
My error. I fixed my first post. In no case does it work with spaces between the label word and :

At my age, I make a lot of typos. It has become so hard to create code any more because I have put up to three typos in a single line. Thanks for pointing it out.
It appears that in the newest version of ImageMagick which is not downloadable from the debian repository, that the label option is of the form
-label labelname
instead of the version now used. However, there is no downloadable armhf/arm64 versions and I need both these as well as the one for AMD64

Post Reply