Page 1 of 1

gravity in operations

Posted: 2010-03-12T16:15:38-07:00
by mkoppanen
Hello,

regarding: http://pecl.php.net/bugs/bug.php?id=17083, is MagickSetImageGravity supposed to affect MagickCompositeImage?

Re: gravity in operations

Posted: 2010-03-12T19:13:26-07:00
by magick
Gravity is not used by the composite method. Instead the command-line parser utilizes gravity with the GravityAdjustGeometry() method:
  • GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
    ...
    (void) CompositeImageChannel(image,channel,image->compose,composite_image,geometry.x,geometry.y);

Re: gravity in operations

Posted: 2010-05-19T12:29:26-07:00
by portante
Can someone explain why only the GravityAdjustGeometry() method is called from the composite command-line parser?

This seems like a natural flow for the API (see the code below).

Thanks, -peter

Code: Select all

/* cc setb.c -I /opt/local/include/ImageMagick -L/opt/local/lib -l MagickWand -o setb */

#include <stdio.h>
#include <wand/magick-wand.h>

#define LOG_MESSAGE(__type, __format, ...) do { fprintf(stderr, "[%06d] %s: " __format, getpid(), __type, ## __VA_ARGS__); fflush(stderr); } while (0)

#define WARN(__format, ...) LOG_MESSAGE("WARNING", __format, ## __VA_ARGS__)

#define ThrowWandException(wand)										\
  {																		\
    char *description;													\
    ExceptionType severity;												\
    description = MagickGetException(wand,&severity);					\
    WARN("MagickWandException: %s %s %ld %s\n", GetMagickModule(), description); \
    description = (char *) MagickRelinquishMemory(description);			\
  } while (0)

#define COND_WAND_EX(status, wand) \
  if (status == MagickFalse) { ThrowWandException(wand); return 1; }

#define ThrowPixelWandException(wand)									\
  do {																	\
    char *description;													\
    ExceptionType severity;												\
    description = PixelGetException(wand,&severity);					\
    WARN("PixelWandException: %s %s %ld %s\n", GetMagickModule(), description); \
    description = (char *) MagickRelinquishMemory(description);			\
  } while (0)

#define COND_PIXEL_EX(status, wand) \
  if (status == MagickFalse) { ThrowPixelWandException(wand); }


int main(int argc, char *argv[]) {
  MagickWandGenesis();

  PixelWand *background = NewPixelWand();
  MagickBooleanType status = PixelSetColor(background, "#ff00ff");
  COND_PIXEL_EX(status, background);

  MagickWand *magick_wand = NewMagickWand();
  if (magick_wand == NULL) {
	fprintf(stderr, "Failed to allocate a magick wand\n");
	return 1;
  }

  status = MagickSetBackgroundColor(magick_wand, background);
  COND_WAND_EX(status, magick_wand);

  status = MagickReadImage(magick_wand, argv[1]);
  COND_WAND_EX(status, magick_wand);

  status = MagickSetImageGravity(magick_wand, CenterGravity);
  COND_WAND_EX(status, magick_wand);

  status = MagickResizeImage(magick_wand, 1650, 2150, BesselFilter, 1.0);
  COND_WAND_EX(status, magick_wand);

  unsigned long iw = MagickGetImageWidth(magick_wand);
  unsigned long ih = MagickGetImageHeight(magick_wand);

  printf("New size: %lu, %lu\n", iw, ih);

  # Here, the X,Y parameters could theoretically be dropped off if ExtentImage obeyed the image gravity.
  status = MagickExtentImage(magick_wand, 1750, 2250, 0, 0);
  COND_WAND_EX(status, magick_wand);

  status = MagickTransformImageColorspace(magick_wand, RGBColorspace);
  COND_WAND_EX(status, magick_wand);

  status = MagickStripImage(magick_wand);
  COND_WAND_EX(status, magick_wand);

  char *pidded_real_path = "./tmp-rgb-stripped.jpg";
  status = MagickWriteImage(magick_wand, pidded_real_path);
  COND_WAND_EX(status, magick_wand);

  MagickWandTerminus();
  return 0;
}