2

I'm trying the following command to convert text to an image:

$ echo test | convert text:- text_box_trimmed.png
convert: ../../coders/txt.c:198: ReadTEXTImage: Assertion `exception->signature == 0xabacadabUL' failed.
Aborted

How can I convert text to an image, using Imagemagick or something else?

3

1 Answer 1

4

Your test command works for me, it looks that your system lacks something.

Anyway, the text format is used rather for paging text on multiple pages. If your goal is to create an image from a short plain text you can try the label format:

convert -background black -fill green -pointsize 84 \
        -font Helvetica label:'Unix&Linux' test.png

Additionally, you may find xargs handy if your text comes from the other command and you need to pipe it to the convert (as in the question):

echo 'Unix&Linux' | xargs -I '{}' convert -background black -fill green \
                    -pointsize 84 -font Helvetica label:'{}' test.png

You may find many useful examples on the Imagemagick site.


Another relatively simply tool would be old good tex:

echo 'Unix&Linux' | cat - <<<'\bye' > test.tex
tex test.tex && dvipng -o test.png test.dvi

But that would work only for very simple task, if you want to add colors or change fonts then dedicated instructions in tex file should be added which makes this inefficient in one-time use in interactive shell.

4
  • I actually am interested not in short snippets of text, but in text of about one or two paragraphs long. I tried the label command but it seems to truncate the text. Any idea of what might my system be missing in order to use text?
    – user84207
    Sep 29, 2017 at 2:26
  • Can I use label to output multiple lines of text?
    – user84207
    Sep 29, 2017 at 4:17
  • @user84207 Then you're trying to chop wood with a razor blade. Use a text processor for that kind of things. Sep 29, 2017 at 7:34
  • @user84207 I don't think label can do that automatically, you would need to add \n in the text, other tools like fmt or fold may help you, for example: echo 'very looooong text' | fold -w 6 | ...
    – jimmij
    Sep 29, 2017 at 13:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .