Sam
Sam

Reputation: 2331

Adding label to exisiting png picture, using convert

I need to add a label onto a png picture, also I need to do a command substitution in order to get a number from a file.

I have something like

convert image.png  -background red  label:'input + `grep max numbers.txt | head -n 1 | awk '{print 2}'`' -gravity Center -append

but I have a very limited understanding of convert, I downloaded it just so I could do this one command

Thank-you

Upvotes: 2

Views: 974

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207345

I suspect you need something like this:

convert -size 100x100 xc:red label:"input + $(awk '/max/{print $2; exit}' numbers.txt)" -gravity center -append result.png

enter image description here

You need to put the label: part in double (rather than single) quotes for the shell to expand and execute it. You do not need grep and head and awk. Awk alone is capable of finding the first occurrence of max and then printing the second field and exiting before finding any other instances.

I assume numbers.txt looks something like this:

a 34
max 32
max 33

Upvotes: 2

Related Questions