2

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

Sam
  • 1,765
  • 11
  • 82
  • 176
  • Please show the format of `numbers.txt` and explain what you are trying to achieve. You almost certainly do not need `grep` and `head` and `awk` - just `awk` will do it all - whatever it is. – Mark Setchell Jun 17 '16 at 21:50
  • I figured this out and included it in my [answer to this post](https://stackoverflow.com/questions/63498671/create-a-captioned-meme-using-python-and-pil) – Sam Aug 19 '21 at 19:51

1 Answers1

2

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • When I tried that I just got convert: delegate library support not built-in '/Library/Fonts//Arial.ttf' (Freetype) @ warning/annotate.c/RenderFreetype/1740. a bunch. Also I guess the red part isn't necessary I just included it cause I didn't really understand convert. I basically just want to take a png image and write one word followed by one number. Also numbers.txt is basically like an html code file. There's no structure that looks like a 34 max 32....... it's just the only time max comes up it's followed by the number which I desire. Does that make sense? – Sam Jun 23 '16 at 20:56
  • Seems odd that you would get that message. Please try `convert label:"test" a.png` – Mark Setchell Jun 23 '16 at 21:13
  • Got this. convert: delegate library support not built-in '/Library/Fonts//Arial.ttf' (Freetype) @ warning/annotate.c/RenderFreetype/1740. convert: delegate library support not built-in '/Library/Fonts//Arial.ttf' (Freetype) @ warning/annotate.c/RenderFreetype/1740. convert: no images defined `a.png' @ error/convert.c/ConvertImageCommand/3235 do that mean it's not installed right or something? – Sam Jun 23 '16 at 21:31
  • I don't understand, that looks like instructions on how to download some software, which I tried but got stuck at cd /usr/local/Cellar/imagemagick/6.8.9-1/etc/ImageMagick-6 because I didn't have this directory – Sam Jun 30 '16 at 22:51
  • Yeah I got this when I tried these instructions 10-228-3-3:.magick Sam$ cd /usr/local/Cellar/imagemagick/6.8.9-1/etc/ImageMagick-6 -bash: cd: /usr/local/Cellar/imagemagick/6.8.9-1/etc/ImageMagick-6: No such file or directory I feel like what I'm trying to do is really trivial, I just want to take a text word from a file and print it to a png image – Sam Jul 05 '16 at 22:13
  • @C.Monster Ok, the bit where you are stuck is about finding your `type.xml` file to edit. If you can't find it, try this command and it will tell you where it is `convert -debug configure -list font 2>&1 | grep -E "Searching|Loading"` – Mark Setchell Jul 06 '16 at 07:16