MagickShadowImage args have no effect

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

MagickShadowImage args have no effect

Post by mkoppanen »

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>

#define ThrowWandException(wand) \
{ \
  char \
    *description; \
 \
  ExceptionType \
    severity; \
 \
  description=MagickGetException(wand,&severity); \
  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
  description=(char *) MagickRelinquishMemory(description); \
  exit(1); \
}


int main() {

        int i = 0;
        PixelWand *pix = NewPixelWand();
       
        MagickWand *shadow = NULL;
        MagickWand *wand = NewMagickWand();

        MagickSetSize(wand, 100, 100);

		PixelSetColor(pix, "black");

        if (!MagickReadImage(wand, "magick:rose")) {
                ThrowWandException(wand);
        }

        MagickWriteImage(wand, "orig.jpg");
        MagickSetImageBackgroundColor(wand, pix);

        for (i = 0; i < 100; i += 10) {
                char fname[256];

                memset(fname, 0, 256);
                sprintf(fname, "img_%d.png", i);

                shadow = CloneMagickWand(wand);

                if (MagickShadowImage(shadow, 50, 1, i, i / 2) == MagickFalse) {
                        ThrowWandException(wand);
                }

                MagickWriteImage(shadow, fname);
                DestroyMagickWand(shadow);
                shadow = NULL;
        }
		DestroyPixelWand(pix);
        DestroyMagickWand(wand);
}
Should the shadow geometry change?
Mikko Koppanen
My blog: http://valokuva.org
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: MagickShadowImage args have no effect

Post by magick »

Try this:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wand/MagickWand.h>

#define ThrowWandException(wand) \
{ \
  char \
    *description; \
\
  ExceptionType \
    severity; \
\
  description=MagickGetException(wand,&severity); \
  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
  description=(char *) MagickRelinquishMemory(description); \
  exit(1); \
}

int main()
{
  PixelWand *background = NewPixelWand();
  MagickWand *rose, *shadow, *merge;
  MagickBooleanType status;

  rose=NewMagickWand();
  if (MagickReadImage(rose,"rose:") == MagickFalse)
    ThrowWandException(rose);
  shadow=CloneMagickWand(rose);
  PixelSetColor(background,"navy");
  MagickSetImageBackgroundColor(shadow,background);
  if (MagickShadowImage(shadow,80,3,5,5) == MagickFalse)
    ThrowWandException(shadow);
  status=MagickAddImage(shadow,rose);
  if (status == MagickFalse)
    ThrowWandException(rose);
  PixelSetColor(background,"none");
  MagickSetImageBackgroundColor(shadow,background);
  merge=MagickMergeImageLayers(shadow,MergeLayer);
  MagickWriteImage(merge,"rose.png");

  DestroyPixelWand(background);
  DestroyMagickWand(merge);
  DestroyMagickWand(shadow);
  DestroyMagickWand(rose);
}
Post Reply