Page 1 of 1
Fitting text to image [SOLVED]
Posted: 2013-03-10T18:01:18-07:00
by Brabantis
Hello,
I am using ImageMagick on a Mac, and I wanted to use it to create a geeklet (for GeekTool) that would display info slightly rotated clockwise. I have a code that would fetch some text, then make a rotated image of it. The code I am using for simple texts is:
Code: Select all
{part of code that fetches the text}| /opt/local/bin/convert -rotate 15 -background none -fill black -pointsize 24 -font Courier label:@- -trim /tmp/label.png
It works fine, but I wanted to make it possible, for lengthier texts, to set the width of the image (before the rotation) and have the text adjusted to it. Until now I only managed to crop it.
Please ask for explanation if I was not clear, I am not a native English speaker.
Thank you!
Re: Fitting text to image
Posted: 2013-03-10T18:19:23-07:00
by fmw42
You need to create the text image before rotation. To get a specific width (before rotation), you need to use -size and remove the pointsize.
So something like the following should work (but in the current version, it is not expanding the text to fill the width). See
viewtopic.php?f=3&t=22946
convert -size 200x -background none -fill black -font arial label:"some text" -rotate 15 output
Re: Fitting text to image
Posted: 2013-03-10T18:35:55-07:00
by Brabantis
Didn't work. From the little I know of coding, your method is for adjusting the size of the letters to fill the width; I just wanted the text to go to the next line whenever it would go over a certain width. Like in Notepad.
Re: Fitting text to image
Posted: 2013-03-10T19:00:11-07:00
by snibgo
(Notepad is a Windows text editor that word-wraps. It needs to know the font size and page margins, of course.)
"label:" can't word-wrap. "caption:" can. See
http://www.imagemagick.org/Usage/text/#caption
As fmw42 says, do the rotation after the "caption:".
Re: Fitting text to image
Posted: 2013-03-10T19:06:09-07:00
by fmw42
Brabantis wrote:Didn't work. From the little I know of coding, your method is for adjusting the size of the letters to fill the width; I just wanted the text to go to the next line whenever it would go over a certain width. Like in Notepad.
Sorry that was not clear in your earlier post. So (as snibgo said) use caption in place of label
convert -size 200x -background none -fill black -font arial caption:"some text" -rotate 15 output
Note that the rotation will make your resulting image bigger than the 200 width. I assume you understand that.
Re: Fitting text to image
Posted: 2013-03-11T02:41:11-07:00
by Brabantis
That didn't work either. There re a couple things I noticed though. First, as far as my limited skill goes I cannot use "label" or "caption" because the text is not fixed, but the result of the previous script. Also "rotate" didn't work if not in the first position, and it did not seem to work with "size".
My problem is that I am writing a widget that displays an RSS feed on my desktop, and I wanted it to fit on a rotated square of parchment; id wouldn't fit if I don't wrap the text.
EDIT: Ok, I found a solution by tweaking the first script. Thanks anyway
Re: Fitting text to image [SOLVED]
Posted: 2013-03-11T07:16:22-07:00
by snibgo
What version IM are you running? If "-rotate" needs to be first, it must be a very old version. If so, I suggest you upgrade.
Re: Fitting text to image [SOLVED]
Posted: 2013-03-11T07:49:47-07:00
by Brabantis
I upgraded last week
Re: Fitting text to image [SOLVED]
Posted: 2013-03-14T16:33:51-07:00
by anthony
If the text is not fixed, you need to generate a caption for each of the text strings, then rotate.
There is no other way to get rotated and word wrapped text, caption (and pango) are the only word wrapping text to image converters in IM.
Re: Fitting text to image [SOLVED]
Posted: 2013-03-15T01:30:04-07:00
by Brabantis
Yes, but I solved by altering the other code, the one that generates RSS feeds