Page 1 of 1

MagickPolaroidImage caption problem

Posted: 2007-12-01T10:16:31-07:00
by el_supremo
When using a "%wx%h" caption with MagickPolaroidImage (in C and ImageMagick 6.3.5 07/31/07 Q8) it always prints the height as 1 but on the command line I get the right info.
I can't figure out why there's a difference, but in the PolaroidImage function in fx.c there is this statement:

Code: Select all

      /*
        Generate caption image.
      */
      caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
which explicitly uses a height of one and caption_image is then used to determine the values of the caption string.
Is this correct?

Pete

Re: MagickPolaroidImage caption problem

Posted: 2007-12-01T10:23:57-07:00
by magick
A few lines down you will find a call to InterpretImageProperties(). Change the caption_image parameter to image and see if that fixes the problem.

Re: MagickPolaroidImage caption problem

Posted: 2007-12-01T12:55:05-07:00
by el_supremo
Yes, that fixes the problem.

Thanks
Pete

Re: MagickPolaroidImage caption problem

Posted: 2007-12-02T11:44:18-07:00
by el_supremo
A followup.
I was using MagickSetImageProperty(m_wand,"caption","%f %wx%h") to set the caption for the polaroid but after some testing and reading the IM code it appears that the command line must be using MagickSetOption(m_wand,"caption","%f %wx%h").

When using MagickSetOption, it must be called before MagickReadImage (and on the command line -caption must precede the input image) or else it is ignored. But when using MagickSetImageProperty it must follow MagickReadImage.
They both appear to set the same thing but are handled slightly differently because before the fix to the code that you suggested, MagickSetOption would cause a caption with the correct image size information but MagickSetImageProperty gave a height of one (with the fix they're both correct).

Since the command line uses MagickSetOption I presume this is the correct function to use in this situation but what is the difference between the two?

And BTW, there's no entry for -caption in http://imagemagick.org/script/command-line-options.php

Pete

Re: MagickPolaroidImage caption problem

Posted: 2007-12-02T13:56:13-07:00
by magick
In general, use MagickSetOption() to set key/value pairs before an image is read and MagickSetImageProperty() after the image is read (as you correctly surmised). We use the MagickCore API SetImageOption() method when interpretting the command the line because caption behaves as a setting not an image operator. After the image is read the caption is interpreted and saved as an image property (e.g. %wx%h, see ReadImage() in magick/constitute.c for details). So for MagickPolaroidImage() the proper method to set the caption is MagickSetImageProperty().