Caption: adding breaklines in the middle of a word

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
BigNoub
Posts: 33
Joined: 2015-12-29T14:49:52-07:00
Authentication code: 1151

Caption: adding breaklines in the middle of a word

Post 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?
BigNoub
Posts: 33
Joined: 2015-12-29T14:49:52-07:00
Authentication code: 1151

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

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
BigNoub
Posts: 33
Joined: 2015-12-29T14:49:52-07:00
Authentication code: 1151

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

Post 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?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

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

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post by magick »

Caption looks for a place to break text up to fit on a line. A space between two numbers is a candidate.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

You might try a non-breaking space, a UTF character that provides a space that shouldn't allow a line break.
snibgo's IM pages: im.snibgo.com
BigNoub
Posts: 33
Joined: 2015-12-29T14:49:52-07:00
Authentication code: 1151

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

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

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

Post 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.
Post Reply