How to know size of text with Mogrify?

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
novito
Posts: 30
Joined: 2013-11-26T17:37:36-07:00
Authentication code: 6789

How to know size of text with Mogrify?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to know size of text with Mogrify?

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