List Info

Thread: caption, word wrap and font size




caption, word wrap and font size
country flaguser name
United States
2007-03-16 12:48:43
HI,

Thank you for your suggestions - I was able to solve my
problem modifying the font!

I have one more question:

I need my text to be aligned in center so I used this on the
command line:

convert - background black -fill white -fort ariblk.ttf
-size 250x110 -gravity Center caption:"Each line should
be in the center..." testCaption.png

and that worked fine. Now I tried to do the same using
PerlMagick, and here is the code:

$title_img->Set(
    background=>'transparent', 
    font=>'C:\WINDOWS\Fonts\ariblk.ttf', 
    fill=>'white', 
    gravity=>'Center', 
    antialias=>'true');
$title_img->Read("caption:$title");

but the problem is the lines are flushed to the left. It
seems that the gravity used in Set is not having an effect.
Does anyone know how to do this properly in perl.

Thanks

Zrinka

| Hi,
| 
| I am trying to fit some text in a limited box and I
understand I can
| do this by using "caption" without specifying
"-pointsize". I tried it
| and it worked. However, I have one more problem - I have
to use
| Arial-Black font and at larger pointsize (most of the text
will be
| between 30 and 40) the space between the lines is very
wide. After
| reading everythign I could on ImageMagick website I
understand that
| this is a feature of the type, and that it cannot be
changed in
| ImageMagick (well at least it is not straight forward),
correct?
| 
Yes.  The font is designed specifically for easy reading of
test
documents. Lots of text. and that means a good line spacing
is needed.
The pointsize actually defines the line spacing rather than
the actual
letter heights.

You will need to find an alturnative font that does not have
such a big
line spacing.  Or re-design Arial-Black for this purpose.

There are lots of fonts available in font servers around the
web, so
something must be availabel for you to use.


Does anyone on the web have any suggestions for minimal line
spaced
fonts?


| I could solve this problem by separating the text into
several strings
| (as many as there are lines of text that were fit into the
box by
| "caption"), and then placing each string (or
line) separately within
| the box. However, for that I would need  to know the
pointsize
| "caption" finally chose. Is there a way to get
to that information -
| the font size "caption' chose to fit the text inside
the box with word
| wrap?
| 
| If I cannot  get that, then I am out of ideas, at least
easiers ones.
| Any suggestion/examples would be greatly appreciated.
| 
Not at this time. sorry.
But the caption algorithm is relativally straight forward.

Captions hard requirement is line length (image width).

Basically it internally tries different pointsizes (using
maths rather
than actual drawing) to find the largest pointsize that just
fits the
user supplied height requirement
That is
    final number of lines due to word wrapping * pointsize
in pixels
is less than or equal to the user supplied image height.

This is a binary search, so only 4 to 5 'guesses' is needed
to figure out the
final pointsize for the caption.  Once it has that it draws
the text.

This can be done yourself in an API, and you could even
lookup the
source code to find out how IM does it internally.


| By the way - I am working with PerlMagick. But I could
switch to
| another API if that would solve my problem (and if
somebody already
| did this and can share some code 
| 
PerlMagick can retrieve the font attributes needed.
I don't know how myself.


Actually I have been thinking about a 'caption' like
auto-size
but for fitting text into a oddly shaped area (as defined by
a mask),
rather than a rectangular area.

This needs two parts.  One to 'best fill a shaped area' with
words at a
specific point size, and return success or failure.  And the
same outer
loop that normal auto-size caption uses.

It is fitting words into a shaped area that is the real
puzzle.

It is currently just a mind puzzle for me at this point, but
if someone
likes to try to work this out. It would be a great little
program, that
could make IM text handling a cut about the rest.







 
____________________________________________________________
________________________
Sucker-punch spam with award-winning protection. 
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/feat
ures_spam.html

_______________________________________________
Magick-users mailing list
Magick-usersimagemagick.org
http://studio.imagemagick.org/mailman/listinfo/magick
-users

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )