Page 1 of 1

Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T04:26:33-07:00
by BigNoub
I'm using ImageMagick 6.9.2-10 Q16 x86_64 2015-12-30 on Lubuntu 14.04, running through shell.

When I use this command:

Code: Select all

echo -n "Dans votre vie, vous mangerez environ 30 000 kilos de nourriture, l’équivalent du poids de 6 éléphants." | convert -background black -fill white -font /usr/share/fonts/arial.ttf -size 465x101 -gravity Center caption:@- "output.jpg"
the output is :

Image

As you can see, the "word" 000 has been cut in the middle, i.e. a breakline has been added in the middle of a word. This problem does not look specific to numbers as I've had the same problem with words with letters.

Can we prevent this behavior?

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T06:44:06-07:00
by magick

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T07:42:41-07:00
by BigNoub
Sorry I just read the full section about Pango and Pango Markup Language but couldn't see a reference to my problem.

Do you mean I should use pango: instead of caption: ?

I tried but it looks like the font size is not automatically adjusted anymore.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T08:24:00-07:00
by magick
Caption can automatically size text to fit in a defined area but does not give you control over the placement of the text. Pango markup allows you to have control over the placement of text but does not do automatic font sizing.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T09:04:53-07:00
by BigNoub
ok so you are saying that caption does not really recognize words in the text and is going to insert a newline anywhere it likes (and not only where there is a space character)? That's what you mean when you say I can't control "placement of the text"?

But then how to explain that 95% of my texts have correct newlines (between words), and the behavior I report above is only in a minority of cases?

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T10:28:28-07:00
by Bonzo
Perhaps the problem is it is breaking on a number. Have you tried putting a word where the number is?

Can you force a line break before the number?

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T12:17:27-07:00
by magick
Caption looks for a place to break text up to fit on a line. A space between two numbers is a candidate.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T13:28:22-07:00
by snibgo
You might try a non-breaking space, a UTF character that provides a space that shouldn't allow a line break.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T13:52:57-07:00
by BigNoub
Thank you all for your replies.

I'm puzzled because I have just tried again the code I posted above in my first message and the numbers aren't cut anymore. Can anyone try it and confirm if they can replicate the problem?

@bonzo : the problem happened with letters too
@magick : there was no space between the two numbers that were on separate lines, plus this happened with letters too (also not separated by a space)
@snibgo : what would this UTF character look like?

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T14:04:53-07:00
by snibgo
@snibgo : what would this UTF character look like?
It would look like a space. It is commonly used on web pages, coded as "& nbsp ;" (without the spaces). UTF contains a number of space characters for different purposes. From vague memory, a particular character is recommended for use as a thousands separator, such as your example.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T15:17:32-07:00
by fmw42
snibgo wrote:
@snibgo : what would this UTF character look like?
It would look like a space. It is commonly used on web pages, coded as "& nbsp ;" (without the spaces). UTF contains a number of space characters for different purposes. From vague memory, a particular character is recommended for use as a thousands separator, such as your example.
That should only work to replace a normal space with a non-breaking space in HTML. I doubt it would prevent an IM break in a set of consecutive zeros, such as 00000. It would also add a space there.

Re: Caption: adding breaklines in the middle of a word

Posted: 2015-12-31T17:21:36-07:00
by magick
We added a patch to ImageMagick 6.3.0 that should resolve the problem. We won't break on digit followed by a number. 6.3.0-0 beta will be available sometime tomorrow.