Long Text in Image (with wordwrap)

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ali

Long Text in Image (with wordwrap)

Post by ali »

hi, i have the problem, that imagemagick dont want to make a image with a text, that is 500 words long or so.

here is what i tried:
convert -background lightblue -fill blue -font test/fonts/font.ttf -size 820x600 caption:'Cum vero graeco interpretaris ut, ...' warp.jpg

imagemagick needs to automatically take the best fontsize, so that the text fill the image. but the programm gives me a "TokenLengthExceedsLimit" exception. well i know, why, the caption-parameter is too long, is there another way to do that what i want? what need i to do, to avoid that error? is there a solution for that?

thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Long Text in Image (with wordwrap)

Post by anthony »

For that length I'm suprized the command line works!

I suggest you feed the text into the command using a file

Code: Select all

   convert .... comment:@file_of_text.txt ....
or a pipeline

Code: Select all

   echo 'text to use" | convert .... comment:@- .... 
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ali

Re: Long Text in Image (with wordwrap)

Post by ali »

ok thanks, that helped me, im using now pipes.

the (php-)projekt generates a big image with 2 boxes on a specific position. in that boxes must be a long text, with variable fontsize. i tried it with more pipes, but it seems to work only with max one pipe.

Code: Select all

convert xc:white -size 800x800 big.jpg
echo 'box1' | convert xc:grey -font xy -size 200x300 caption:@- muff:- | composite -geometry +150+50 - big.jpg big.jpg
echo 'box2' | convert xc:grey -font xy -size 200x300 caption:@- muff:- | composite -geometry +500+50 - big.jpg big.jpg
it would work with tempfiles, but tempfiles make it slower... is there a easy solution for my problem? has someone a better idea for a solution?
thanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Long Text in Image (with wordwrap)

Post by anthony »

Specify the -size for the caption: but NOT the -pointsize. IM will resize the text to fit into the box with word wrapping..

See IM Examples Caption...
http://www.imagemagick.org/Usage/text/#caption

You can also set a centered justification using -gravity if you like.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ali

Re: Long Text in Image (with wordwrap)

Post by ali »

tanks but thats not my problem, i solved it, my problem are the two(!) pipes, with one pipe and tempfiles it works perfect, but i dont want use tempfiles. so my question was how to modify my lines there, so that it works with 2(!) pipes in one line...

tanks
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Long Text in Image (with wordwrap)

Post by anthony »

Pipes are actually a shell scripting problem.

Try using a BASH shell script which can automaticaly create piped filenames.
That means you can do things like.

Code: Select all

   convert <( convert logo: gif:- ) <( convert rose: jpg:- )  -composite multi-pipe-image.gif
The <(...) executes the command and replaces it with a 'pipe file' which the outer command will read from (once only). Strange but it works, and you can use multiple times with multiple command and pipeline streams.

This is however SHELL command process handling, and not IM image handling.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply