I've been playing around a bit more with font metrics and the info I gave you is wrong (sorry). But the method you're using still has problems.
When you use Annotate to write on an image, it gets all its information about the font from the *drawing* wand. Setting MagickSetFont will have no effect.
Also, using MagickSetSize will have no effect on the magick wand - it *sets* the size but does not *change* the size.
I also used the wrong info when setting the new size of the image. The bounding box gives info about the size of one letter. We need to use the information about the width and height of the text which are in elements [4] and [5] of the metrics.
This code should get you on the right track:
Code: Select all
drawing_wand = NewDrawingwand();
banner_txt_str_wand = NewMagickWand();
MagickReadImage(banner_txt_str_wand,"xc:");
// Set the font information in the drawing wand
DrawSetFontSize(drawing_wand,font_size);
DrawSetFont(drawing_wand,banner->txt_font_desc);
// get the font metrics
font_metrics = MagickQueryFontMetrics(banner_txt_str_wand, drawing_wand, banner->txt_str);
// extend the size of the image - I think this is the right one to use
// but works for me in this case
MagickExtentImage(banner_txt_str_wand,font_metrics[4],font_metrics[5],0,0);
// Annotate the image - Note the calculation of the y value which is
// because the text metrics use an origin in the lower left whereas IM has
// its origin at top left
MagickAnnotateImage(banner_txt_str_wand,drawing_wand, 0 ,font_metrics[8]+ font_metrics[5], 0.0 ,banner->txt_str);
// Now write the magickwand image
Change the font name and size
Pete