Page 1 of 1

How to know size of text with Mogrify?

Posted: 2013-12-17T14:34:02-07:00
by novito
I want to write some text to an Image with Mogrify. I am using a wrapper around Mogrify for Ruby called Minimagick, and my code looks like this:

Code: Select all

composed_image.combine_options do |c|
  c.fill(price_color)    
  c.pointsize '24'                                                                                             
  c.draw "text 30,40 'Hi this is my text'"                                                                            
end
Somehow it would be great to know how much width and height that text is going to take. I would like that to avoid the text to be cut by the end of the image that is being drawn to. Is there anyway I can know which width/height a particular text with particular pointsize will take?

Thanks

Re: How to know size of text with Mogrify?

Posted: 2013-12-17T17:23:01-07:00
by fmw42
mogrify is very simplistic and does not have all the features of convert. It will only process images to images and not images to information. For that you need to use convert and label: or caption: to create the image and get its size information or better use -debug annotate. See http://www.imagemagick.org/Usage/text/#font_info

convert -background white -fill black -font arial -pointsize 24 label:"this is a test" -format "%wx%h\n" info:
129x28