Setting caption font properties using MagickWand API

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Setting caption font properties using MagickWand API

Post by mkoppanen »

How are caption: font type, font color and other font properties set using MagickWand API?
Mikko Koppanen
My blog: http://valokuva.org
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Setting caption font properties using MagickWand API

Post by mkoppanen »

Well, I had some extra time during the evening so I came up with this solution: Adding MagickSetFont and MagickSetFontSize to wand/magick-property.

This however does not seem to be a complete solution (MagickSetFontFamily? Font color?). I got a semi-ready patch for adding MagickSetFont and MagickSetFontSize, so drop me a note if this seems like a reasonable approach and I will continue my work on them.
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting caption font properties using MagickWand API

Post by magick »

Post your patches here or post a URL to your patch file and we will get them into the next point release of ImageMagick.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Setting caption font properties using MagickWand API

Post by mkoppanen »

The patch got incredibly messy because there are some chars that my editor seems to be stripping. Nano shows them as ^L. This is the first time I checking to code in the ImageMagick side so this might not be the optimal way:

But here is magick-property.c:

Code: Select all

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k S e t F o n t                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickSetFont() sets the font for the MagickWand.
%
%  The format of the MagickSetFont method is:
%
%      MagickBooleanType MagickSetFont(MagickWand *wand, const char *font)
%
%  A description of each parameter follows:
%
%    o wand: The magick wand.
%
%    o font: the font
%
*/
WandExport MagickBooleanType MagickSetFont(MagickWand *wand, const char *font)
{
  if ((font == (const char *) NULL) || (*font == '\0'))
    return(MagickFalse);

  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);

  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);

  (void) CloneString(&wand->image_info->font,font);
  return(MagickTrue);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k G e t F o n t                                                 %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickGetFont() gets the font from the MagickWand.
%
%  The format of the MagickGetFont method is:
%
%      char *MagickGetFont(MagickWand *wand)
%
%  A description of each parameter follows:
%
%    o wand: The magick wand.
%
*/
WandExport char *MagickGetFont(MagickWand *wand)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);

  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);

  if(wand->image_info->font != (char *) NULL)
	return(AcquireString(wand->image_info->font));
  return((char *) NULL);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k S e t F o n t S i z e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickSetFontSize() sets the font size for the MagickWand.
%
%  The format of the MagickSetFontSize method is:
%
%      MagickBooleanType MagickSetFontSize(MagickWand *wand, const double pointsize)
%
%  A description of each parameter follows:
%
%    o wand: The magick wand.
%
%    o pointsize: the size of the font
%
*/
WandExport MagickBooleanType MagickSetFontSize(MagickWand *wand, const double pointsize)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);

  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);

  wand->image_info->pointsize = pointsize;
  return(MagickTrue);
}

/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   M a g i c k G e t F o n t S i z e                                         %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  MagickGetFontSize() gets the font size from the MagickWand.
%
%  The format of the MagickGetFontSize method is:
%
%      double MagickGetFontSize(MagickWand *wand)
%
%  A description of each parameter follows:
%
%    o wand: The magick wand.
%
*/
WandExport double MagickGetFontSize(MagickWand *wand)
{
  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);

  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);

  return(wand->image_info->pointsize);
}
I'll try to figure out a clean way to create the patch (all thou changes in magick-property.h are not hard to add).
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting caption font properties using MagickWand API

Post by magick »

We put your patches in ImageMagick 6.3.6-4 Beta. The updates will be available in a day or two.
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Setting caption font properties using MagickWand API

Post by mkoppanen »

Thanks!

I was wondering should there be other accessors also? And I couldn't find anything to set polaroid properties trough magickwand (polaroid could use some space for a caption in the bottom side).
Mikko Koppanen
My blog: http://valokuva.org
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Setting caption font properties using MagickWand API

Post by mkoppanen »

I found the MagickSetBackgroundColor accessor. Next thing might be font color? (I think then all is done for caption:)
Mikko Koppanen
My blog: http://valokuva.org
Post Reply