Hi there! After search and try for weeks I finally decided to ask you, either if its not possible, to render text (multi- or singleline) into a new image?
So what I really want is a command, to send the following parameters:
- maxwidth
- text
- font to use (like C:\Inetpub\wwwroot\myweb\fonts\arial.ttf)
- fontsize
- fontcolor
- kerning
- wordspacing
- leading
- backgroundcolor ( a color or 'none' )
- path to the file to create (like C:\inetpub\wwwroot\myweb\text1.png)
The fontsize should not be influenced by the image-dimensions, like caption does. Also it would be great to keep the maxwidth optional, so I would have two methods, encapsulating the commands, one for single line text (without maxwidth) and one with multiline text (maximal width by maxwidth). The magick is to find out
- the width and height if the text is singleline
- the height if the text is multiline
All I want is to render the text into a new image so I can resolve the width & height of the image as text bounds after creation and an auto-breaking text if I specify a maxwidth.
Does anyone know if its possible to do this? And if, how...?
Thanks!
Render text to new image
-
- Posts: 4
- Joined: 2011-05-17T08:09:34-07:00
- Authentication code: 8675308
Re: Render text to new image
I thought you could add a pointsize to caption; anyway try:
If this works try adding your other options.
Code: Select all
convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 -fill black\\
-gravity NorthWest caption:"The quick red fox jumped over the lazy brown dog." \\
-flatten caption1.jpg
Re: Render text to new image
fmw42 has just pointed out I have made a mistake - posted some very old code and the line continuations are incorrect.
My mind has gone blank as I normaly use php, is \ correct?
Code: Select all
convert -size 230x130 -background lightblue -font verdana.ttf -pointsize 25 -fill black \
-gravity NorthWest caption:"The quick red fox jumped over the lazy brown dog." \
-flatten caption1.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Render text to new image
I beleive that \ is correct for Linux/Mac (unix) and ^ for Windows as the line continuation symbol
-
- Posts: 4
- Joined: 2011-05-17T08:09:34-07:00
- Authentication code: 8675308
Re: Render text to new image
Thanks for your help! The code works, it keeps the height dynamic if I use it like that:
So I can use it for multiline text. But how can I work with single-line text? In that case I need to get the width...
Code: Select all
convert -size 400x -background lightblue -fill #ffcc00 -font C:\Inetpub\wwwroot\fonts\verdana.ttf -pointsize 25 -fill black -gravity NorthWest caption:"The quick red fox jumped over the lazy brown dog." -flatten C:\Inetpub\wwwroot\caption.jpg
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Render text to new image
for no automatic word wrapping use label: instead of caption. You can include newlines or '\n' in the label for a DIY multi-line label.
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/text/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
-
- Posts: 4
- Joined: 2011-05-17T08:09:34-07:00
- Authentication code: 8675308
Re: Render text to new image
Thanks a lot! I think that´s what I need for single line text.
The command I use for single line text is a following:
The command I use for single line text is a following:
Code: Select all
-background #666666 -fill #ffffff -font C:\Inetpub\wwwroot\test\fonts\comicbd.ttf -interword-spacing 10 -kerning 4 -pointsize 10 -gravity West -size x22 label:"Lorem dolor sit amet" -flatten C:\Inetpub\wwwroot\test\201105190217-9675963.png
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Render text to new image
That is just arguments, not a command. You can't run "-background" as a command!
Why the -flatten?
Only one image is in memory! Flatten would do nothing in this case.
Why the -flatten?
Only one image is in memory! Flatten would do nothing in this case.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/