Page 1 of 1

Setting caption font properties using MagickWand API

Posted: 2007-10-28T12:20:01-07:00
by mkoppanen
How are caption: font type, font color and other font properties set using MagickWand API?

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-28T14:38:52-07:00
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.

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-28T15:19:24-07:00
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.

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-29T07:04:43-07:00
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).

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-29T07:58:39-07:00
by magick
We put your patches in ImageMagick 6.3.6-4 Beta. The updates will be available in a day or two.

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-29T08:02:33-07:00
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).

Re: Setting caption font properties using MagickWand API

Posted: 2007-10-29T14:32:48-07:00
by mkoppanen
I found the MagickSetBackgroundColor accessor. Next thing might be font color? (I think then all is done for caption:)