Discussion:
Adding text in a size proportional to the image?
Terry Carmen
2011-01-04 17:17:38 UTC
Permalink
I'm trying to add some text to my images that are being
hot-linked from other websites.

Adding the text works OK, however the images vary wildly in size, and
once they're scaled in the browser, the text becomes illegible, so,
I'd like to size the text to be a percentage of the image height, not
a fixed point size.

For example, if the image is 400px high, I'd like 40px text. If the
image is 4000px high, I'd like 400px text.

Can anybody toss me a clue on how I can accomplish this?

My current command is:

convert "test.gif"
-font "/path/to/font/Loma.ttf"
-pointsize 32
-geometry x500
-gravity NorthWest
-draw "text 4,4 'This text goes on the image'" gif:-

Any suggestions?

Thanks!

Terry


 
Anthony Thyssen
2011-01-05 05:08:40 UTC
Permalink
On Tue, 04 Jan 2011 12:17:38 -0500
magick-users-***@imagemagick.org wrote:
| I'm trying to add some text to my images that are being
| hot-linked from other websites.
|
| Adding the text works OK, however the images vary wildly in size, and
| once they're scaled in the browser, the text becomes illegible, so,
| I'd like to size the text to be a percentage of the image height, not
| a fixed point size.
|
| For example, if the image is 400px high, I'd like 40px text. If the
| image is 4000px high, I'd like 400px text.
|
| Can anybody toss me a clue on how I can accomplish this?
|
| My current command is:
|
| convert "test.gif"
| -font "/path/to/font/Loma.ttf"
| -pointsize 32
| -geometry x500
| -gravity NorthWest
| -draw "text 4,4 'This text goes on the image'" gif:-
|
| Any suggestions?

Set a label -size limit instead of a point size, and text of the right
size will be generated to fit.

See IM Examples, Text Labels, Best fit
http://www.imagemagick.org/Usage/text/#label_bestfit

Also note that pointsize represents the text linespacing, at the
current density or resolution (72 by default). however actual
size of the draw text on a line does not actually have any bearing
on the pointsize. It depends on what the creator of the font defined.

See the section on Pointsize
http://www.imagemagick.org/Usage/text/#pointsize

Anthony Thyssen ( System Programmer ) <***@griffith.edu.au>
--------------------------------------------------------------------------
Occult Primer... Chapter Fifteen... Elementry Necromancy
Lesson One: Correct use of a Shovel -- Terry Pratchett, "Jingo"
--------------------------------------------------------------------------
Anthony's Castle http://www.cit.griffith.edu.au/~anthony/
Terry Carmen
2011-01-05 16:48:16 UTC
Permalink
Post by Anthony Thyssen
On Tue, 04 Jan 2011 12:17:38 -0500
| I'm trying to add some text to my images that are being
| hot-linked from other websites.
|
| Adding the text works OK, however the images vary wildly in size, and
| once they're scaled in the browser, the text becomes illegible, so,
| I'd like to size the text to be a percentage of the image height, not
| a fixed point size.
|
| For example, if the image is 400px high, I'd like 40px text. If the
| image is 4000px high, I'd like 400px text.
|
| Can anybody toss me a clue on how I can accomplish this?
|
|
| convert "test.gif"
| -font "/path/to/font/Loma.ttf"
| -pointsize 32
| -geometry x500
| -gravity NorthWest
| -draw "text 4,4 'This text goes on the image'" gif:-
|
| Any suggestions?
Set a label -size limit instead of a point size, and text of the right
size will be generated to fit.
See IM Examples, Text Labels, Best fit
   http://www.imagemagick.org/Usage/text/#label_bestfit
I'm not sure how this helps, since I still need to know the image size to select an appropriate label size.

Is there any sort of option to specify text size as a percentage of image size?

Thanks!

Terry
Fred Weinhaus
2011-01-06 18:03:06 UTC
Permalink
One suggestion, crop out the part of the image that you want to fill
with the text to the same size as the image. Use your percentage to
figure out what to crop. Then use label: rather than draw with no
pointsize. That will draw the text to fill the width or height to the
best size font. Then composite the cropped text back into the same
place it was cropped in your image.

Or compute the size you want (width or height) use a transparent
background with label: to create a new image and then overlay it
where you want onto your image.

see http://www.imagemagick.org/Usage/text/#label and
http://www.imagemagick.org/Usage/layers/#convert
Post by Terry Carmen
I'm trying to add some text to my images that are being
hot-linked from other websites.
Adding the text works OK, however the images vary wildly in size, and
once they're scaled in the browser, the text becomes illegible, so,
I'd like to size the text to be a percentage of the image height, not
a fixed point size.
For example, if the image is 400px high, I'd like 40px text. If the
image is 4000px high, I'd like 400px text.
Can anybody toss me a clue on how I can accomplish this?
Terry Carmen
2011-01-06 18:20:59 UTC
Permalink
Post by Fred Weinhaus
One suggestion, crop out the part of the image that you want to fill
with the text to the same size as the image. Use your percentage to
figure out what to crop.  Then use label: rather than draw with no
pointsize. That will draw the text to fill the width or height to the
best size font. Then composite the cropped text back into the same
place it was cropped in your image.
I ended up just calculating an appropriate point size, and passing that to convert.

Being able to specify the text size as a percentage of image height or width just seemed like something that convert would have been able to handle on it's own, but it's not a big problem. I just thought I was missing it in the docs somewhere.

Thanks for the help, everybody.

Terry
John Culleton
2011-01-13 22:38:57 UTC
Permalink
Post by Fred Weinhaus
One suggestion, crop out the part of the image that you want to
fill with the text to the same size as the image. Use your
percentage to figure out what to crop. Then use label: rather than
draw with no pointsize. That will draw the text to fill the width
or height to the best size font. Then composite the cropped text
back into the same place it was cropped in your image.
Or compute the size you want (width or height) use a transparent
background with label: to create a new image and then overlay it
where you want onto your image.
see http://www.imagemagick.org/Usage/text/#label and
http://www.imagemagick.org/Usage/layers/#convert
Post by Terry Carmen
I'm trying to add some text to my images that are being
hot-linked from other websites.
Adding the text works OK, however the images vary wildly in size,
and once they're scaled in the browser, the text becomes
illegible, so, I'd like to size the text to be a percentage of
the image height, not a fixed point size.
For example, if the image is 400px high, I'd like 40px text. If
the image is 4000px high, I'd like 400px text.
Can anybody toss me a clue on how I can accomplish this?
_______________________________________________
Magick-users mailing list
http://studio.imagemagick.org/mailman/listinfo/magick-users
Or:
Make the picture larger.
Label it.
Make it smaller again.
--
John Culleton
Create Book Covers with Scribus:
http://www.booklocker.com/p/books/4055.html
Typesetting and indexing http://wexfordpress.com
book sales http://wexfordpress.net
Free barcode: http://www.tux.org/~milgram/bookland/
Fred Weinhaus
2011-01-06 18:05:23 UTC
Permalink
Not that I know about -- only pointsize or automatic as in label: and caption:

But you can probably look up the conversion from pointsize to pixels
for any given font somewhere on the internet.
Post by Terry Carmen
Is there any sort of option to specify text size as a percentage of
image size?
Continue reading on narkive:
Loading...