示例#1
0
int barcode_to_png (char *image_name) {
  MagickWand *magick_wand;
  MagickBooleanType status;

  int width, height, pad, half_pad;

  /* read a barcode image */
  MagickWandGenesis();
  magick_wand = NewMagickWand();
  MagickSetResolution(magick_wand, 300, 300);
  status = MagickReadImage(magick_wand, image_name);
  if (status == MagickFalse) ThrowWandException(magick_wand, 1);

  /* trim the image, resample it, and pad it by [10% of the long side] per side */
  MagickTrimImage(magick_wand, 10);
  width = MagickGetImageWidth(magick_wand);
  height = MagickGetImageHeight(magick_wand);
  pad = determine_padding(width, height);
  half_pad = round(pad/2);
  MagickExtentImage(magick_wand, width+pad, height+pad, -half_pad, -half_pad);
  
  /* write image (a PNG version and a formatted PS version) */
  status=MagickWriteImage(magick_wand, chop_path(image_name, ".png"));
  if (status == MagickFalse) ThrowWandException(magick_wand, 2);
  status=MagickWriteImage(magick_wand, chop_path(image_name, ".ps"));
  if (status == MagickFalse) ThrowWandException(magick_wand, 2);

  /* clean up */
  magick_wand=DestroyMagickWand(magick_wand);
  MagickWandTerminus();

  return 0;
}
示例#2
0
apr_status_t
dims_extent_operation (dims_request_rec *d, char *args, char **err) {
    MagickStatusType flags;
    RectangleInfo rec;
    
    flags = ParseAbsoluteGeometry(args, &rec);
    if(!(flags & AllValues)) {
        *err = "Parsing extent geometry failed";
        return DIMS_FAILURE;
    }
    
    PixelWand *p_wand = NewPixelWand();
    long w,h;
    int x, y;
    
    PixelSetColor(p_wand, "white");
    
    w = MagickGetImageWidth(d->wand);
    h = MagickGetImageHeight(d->wand);
    
    MagickSetImageBackgroundColor(d->wand,p_wand);
    
    x = (w - rec.width) / 2;
    y = (h - rec.height) / 2;
    MAGICK_CHECK(MagickExtentImage(d->wand,rec.width, rec.height, x, y), d);
    
    return DIMS_SUCCESS;   
}