Exemplo n.º 1
0
int magickRotateImage(const char *imageFile, const char *outputImage, double degree){
    MagickBooleanType status;
    MagickWand *magick_wand;

    PixelWand * bg = malloc(sizeof(PixelWand *));
    /*
      Read an image.
    */
    MagickWandGenesis();
    magick_wand=NewMagickWand();  
    status=MagickReadImage(magick_wand, (char *)imageFile);
    if (status == MagickFalse){
      ThrowWandException(magick_wand);
    }
    /*
      Turn the images into a thumbnail sequence.
    */
    MagickResetIterator(magick_wand);
    while (MagickNextImage(magick_wand) != MagickFalse)
      MagickRotateImage(magick_wand, bg, degree);
//    MagickSetImageCompression(magick_wand, MW_JPEGCompression);
//    MagickUnsharpMaskImage( magick_wand, 4.5, 4.0, 4.5, 0.02 );
    /*
      Write the image then destroy it.
    */
    status=MagickWriteImages(magick_wand, (char *)outputImage, MagickTrue);
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    magick_wand=DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    return status;
}
Exemplo n.º 2
0
int magickResizeImage(const char *imageFile, const char *outputImage, int columns, int rows, int magickFilter, double blur){
    MagickBooleanType status;

    MagickWand *magick_wand;

    /*
      Read an image.
    */
    MagickWandGenesis();
    magick_wand=NewMagickWand();  
    status=MagickReadImage(magick_wand, (char *)imageFile);
    if (status == MagickFalse){
      ThrowWandException(magick_wand);
    }
    /*
      Turn the images into a thumbnail sequence.
    */
    MagickResetIterator(magick_wand);
    while (MagickNextImage(magick_wand) != MagickFalse)
      MagickResizeImage(magick_wand, columns, rows, LanczosFilter, blur);
    /*
      Write the image then destroy it.
    */
    status=MagickWriteImages(magick_wand, (char *)outputImage, MagickTrue);
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    magick_wand=DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    return status;
    
}
Exemplo n.º 3
0
int magickChopImage(const char *imageFile, const char *outputImage, int width, int height, int xPos, int yPos){
    MagickBooleanType status;

    MagickWand *magick_wand;

    /*
      Read an image.
    */
    MagickWandGenesis();
    magick_wand=NewMagickWand();  
    status=MagickReadImage(magick_wand, (char *)imageFile);
    if (status == MagickFalse){
      ThrowWandException(magick_wand);
    }
    /*
      Turn the images into a thumbnail sequence.
    */
    MagickResetIterator(magick_wand);
    while (MagickNextImage(magick_wand) != MagickFalse)
      MagickChopImage(magick_wand, width, height, xPos, yPos);
    /*
      Write the image then destroy it.
    */
    status=MagickWriteImages(magick_wand, (char *)outputImage, MagickTrue);
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    magick_wand=DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    return status;
}
Exemplo n.º 4
0
int magickModulateImage(const char *imageFile, const char *outputImage, double brightness, double saturation, double hue){
    MagickBooleanType status;

    MagickWand *magick_wand;

    /*
      Read an image.
    */
    MagickWandGenesis();
    magick_wand=NewMagickWand();  
    status=MagickReadImage(magick_wand, (char *)imageFile);
    if (status == MagickFalse){
      ThrowWandException(magick_wand);
    }
    /*
      Turn the images into a thumbnail sequence.
    */
    MagickResetIterator(magick_wand);
    while (MagickNextImage(magick_wand) != MagickFalse)
      MagickModulateImage(magick_wand, brightness, saturation, hue);
    /*
      Write the image then destroy it.
    */
    status=MagickWriteImages(magick_wand, (char *)outputImage, MagickTrue);
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    magick_wand=DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    return status;
}
Exemplo n.º 5
0
caddr_t bif_im_CropAndResizeImageBlob(caddr_t * qst, caddr_t * err, state_slot_t ** args)
  {
  im_env_t env;
  caddr_t res;
  unsigned long width = bif_long_arg (qst, args, 2, "IM CropAndResizeImageBlob");
  unsigned long height = bif_long_arg (qst, args, 3, "IM CropAndResizeImageBlob");
  long x = bif_long_arg (qst, args, 4, "IM CropAndResizeImageBlob");
  long y = bif_long_arg (qst, args, 5, "IM CropAndResizeImageBlob");
  long h_size = bif_long_arg (qst, args, 6, "IM ResizeImageBlob");
  long v_size = bif_long_arg (qst, args, 7, "IM ResizeImageBlob");
  double blur = bif_double_arg (qst, args, 8, "IM ResizeImageBlob");
  long filter = bif_long_arg (qst, args, 9, "IM ResizeImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM CropAndResizeImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 10, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
      MagickResizeImage (env.ime_magick_wand, h_size, v_size, filter, blur);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 6
0
GmImp::~GmImp()
{
    if (this->wand != nullptr) {
        MagickResetIterator(this->wand);
        DestroyMagickWand(this->wand);
    }
}
int convert_adjoin (MagickWand *input, MagickWand **output, convert_t *opts) {
  unsigned long pages = MagickGetNumberImages(input);
  uint32_t start = opts->page_start;
  uint32_t end = opts->page_end;

  if (pages < 2 || opts->format == INFO) return MagickPass;

  if (end && end < pages) {
    if (convert_remove_range(input, end, pages) != MagickPass) return MagickFail;
    pages = end;
  }

  if (start && pages) {
    start = MIN(start-1, pages);
    if (convert_remove_range(input, 0, start) != MagickPass) return MagickFail;
    pages -= start;
  }

  if (!pages) return MagickFail;

  if (!opts->split) {
    MagickResetIterator(input);
    input = MagickAppendImages(input, 1);
  }
  *output = input;
  if (*output == NULL) return MagickFail;

  if (opts->scale_height && !(opts->scale_options & MULTIPAGE)) opts->scale_height *= pages;

  return MagickPass;
}
int write_archive_from_mem(char *outname, MagickWand *wand)
{
  int archiveSize = 0;
  int pageNumber = 1;
  struct archive *a;
  struct archive_entry *entry;
  a = archive_write_new();
  archive_write_set_format_ustar(a);
  archive_write_open_filename(a, outname);
  char filename[13];
  MagickResetIterator(wand);
  MagickNextImage(wand); // Has to be called after MagickResetIterator to set the first picture as the current
  do { 
    unsigned char *data;
    size_t size;
    data = MagickWriteImageBlob(wand, &size);
    entry = archive_entry_new();
    snprintf(filename, 13, "page_%d", pageNumber++);
    archive_entry_set_pathname(entry, filename);
    archive_entry_set_size(entry, size);
    archive_entry_set_filetype(entry, AE_IFREG);
    archive_entry_set_perm(entry, 0644);
    archive_write_header(a, entry);
    archiveSize += archive_write_data(a, data, size);
    archive_entry_free(entry);
  } while (MagickNextImage(wand));
  archive_write_close(a);
  archive_write_free(a);
  return archiveSize;
}
Exemplo n.º 9
0
caddr_t bif_im_ConvertImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
        char out_name[64];
  caddr_t format = bif_string_arg (qst, args, 2, "IM ConvertImageBlob");
  im_init (&env, qst, args, "IM ConvertImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 3, -1);
  im_read (&env);

        if (env.ime_input_ext != NULL)
        {
                if (strlen(format) < 30)
                {
                        strcpy(out_name, "image.");                                                                                                                                                               
                        strcat(out_name, format);                                                                                                                                                              
                }
	}
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    env.ime_status = MagickSetImageFormat (env.ime_magick_wand, format);
    MagickSetFilename (env.ime_magick_wand, out_name);
    if (env.ime_status == MagickFalse)
      im_leave_with_error (&env, "22023", "IM001", "bif_im_ConvertImageBlob cannot convert image");
    }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 10
0
/**
 * @brief lua_convert the function of convert image by lua
 *
 * @param im the im object which will be convert
 * @param req the zimg request
 *
 * @return 1 for OK and -1 for fail
 */
int lua_convert(MagickWand *im, zimg_req_t *req)
{
    int ret = -1;
    LOG_PRINT(LOG_DEBUG, "lua_convert: %s", req->type);
    MagickResetIterator(im);
    MagickSetImageOrientation(im, TopLeftOrientation);

    if(req->thr_arg->L != NULL)
    {
        lua_arg *larg = (lua_arg *)malloc(sizeof(lua_arg));
        if(larg == NULL)
            return -1;
        larg->lua_ret = ret;
        larg->trans_type = req->type;
        larg->img = im;
        pthread_setspecific(thread_key, larg);
        //luaL_dofile(req->thr_arg->L, settings.script_name);
        lua_getglobal(req->thr_arg->L, "f");
        if(lua_pcall(req->thr_arg->L, 0, 0, 0) != 0)
        {
            LOG_PRINT(LOG_WARNING, "lua f() failed!");
        }

        ret = larg->lua_ret;
        free(larg);
    }
    else
        LOG_PRINT(LOG_WARNING, "no lua_stats, lua_convert failed!");

    return ret;
}
Exemplo n.º 11
0
caddr_t bif_im_DeepZoom4to1 (caddr_t * qst, caddr_t * err, state_slot_t ** args)
  {
  im_env_t env;
  caddr_t res;
  int fmt_is_set = 0;
  int image_ctr;
  im_init (&env, qst, args, "IM DeepZoom4to1");
  im_set_background (&env, "#000000");
  env.ime_target_magick_wand = NewMagickWand ();
  if (MagickFalse == MagickNewImage (env.ime_target_magick_wand, 256, 256, env.ime_background))
    im_leave_with_error (&env, "22023", "IM001", "Can not make new image");
  if (MagickFalse == MagickSetImageType (env.ime_target_magick_wand, TrueColorType))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image type");
  if (MagickFalse == MagickSetImageDepth (env.ime_target_magick_wand, 16))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image depth");
  if (MagickFalse == MagickSetImageExtent (env.ime_target_magick_wand, 256, 256))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image extent");
  if (MagickFalse == MagickSetImageBackgroundColor (env.ime_target_magick_wand, env.ime_background))
    im_leave_with_error (&env, "22023", "IM001", "Can not set image background");
  image_ctr = BOX_ELEMENTS (args) / 2;
  if (image_ctr > 4)
    image_ctr = 4;
  while (0 < image_ctr--)
    {
      if (DV_DB_NULL == DV_TYPE_OF (bif_arg (qst, args, image_ctr*2, "IM DeepZoom4to1")))
        continue;
      im_env_set_input_blob (&env, image_ctr * 2);
      /*im_env_set_blob_ext (&env, 2);*/
      im_read (&env);
      MagickResetIterator (env.ime_magick_wand);
      while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
        {
          unsigned long v_size, h_size;
          if (!fmt_is_set)
            {
              if (MagickFalse == MagickSetImageFormat (env.ime_target_magick_wand, MagickGetImageFormat (env.ime_magick_wand)))
                im_leave_with_error (&env, "22023", "IM001", "Can not set image format");
              fmt_is_set = 1;
            }
          h_size = MagickGetImageWidth (env.ime_magick_wand);
          v_size = MagickGetImageHeight (env.ime_magick_wand);
          if ((256 < h_size) || (256 < v_size))
            continue;
          MagickResizeImage (env.ime_magick_wand, h_size/2, v_size/2, BoxFilter, 1.0);
          if (MagickFalse == MagickCompositeImage (env.ime_target_magick_wand, env.ime_magick_wand, OverCompositeOp, (image_ctr & 1) * 128, (image_ctr & 2) * 64))
            im_leave_with_error (&env, "22023", "IM001", "Can not composite image");
        }
      im_reset_read (&env);
    }
  MagickProfileImage (env.ime_target_magick_wand, "*", NULL, 0);
  DestroyMagickWand (env.ime_magick_wand);
  env.ime_magick_wand = env.ime_target_magick_wand;
  env.ime_target_magick_wand = NULL;
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 12
0
 void scale_height(size_t height)
 {
     size_t width = (size_t)round(width_ * ((double)height/height_));
     
     MagickResetIterator(magick_wand);
     while (MagickNextImage(magick_wand) != MagickFalse) {
         MagickResizeImage(magick_wand,width,height,LanczosFilter,1.0);
     }
     width_ = width;
     height_ = height;
 }
Exemplo n.º 13
0
 void crop(size_t width, size_t height, size_t x, size_t y)
 {
     MagickResetIterator(magick_wand);
     while (MagickNextImage(magick_wand) != MagickFalse) {
         if(MagickFalse == MagickCropImage(magick_wand,width,height,x,y))
         {
             throw("An error occured");
         }
     }
     width_ = width;
     height_ = height;
 }
Exemplo n.º 14
0
 void box(size_t width, size_t height, char floated)
 {
     double width_ratio = (double)width/width_;
     double height_ratio = (double)height/height_;
     size_t new_width, new_height, crop_x, crop_y;
     if(width_ratio > height_ratio)
     {
         new_width = width;
         new_height = (size_t)(height_ * width_ratio);
         crop_x = 0;
         crop_y = 0;
         
         if((floated & EIM_FLOAT_BOTTOM) == EIM_FLOAT_BOTTOM)
         {
             crop_y = new_height - height;
         }
         else if((floated & EIM_FLOAT_TOP) == EIM_FLOAT_TOP)
         {
             crop_x = 0;
         }
         else//if((floated & EIM_FLOAT_CENTER) == EIM_FLOAT_CENTER)
         {
             crop_y = (size_t)(new_height / 2.0 - height / 2.0);
         }
     }
     else
     {
         new_width = (size_t)(width_ * height_ratio);
         new_height = height;
         crop_y = 0;
         if((floated & EIM_FLOAT_RIGHT) == EIM_FLOAT_RIGHT)
         {
             crop_x = new_width - width;
         }
         else if((floated & EIM_FLOAT_LEFT) == EIM_FLOAT_LEFT)
         {
             crop_x = 0;
         }
         else//if((floated & EIM_FLOAT_CENTER) == EIM_FLOAT_CENTER)
         {
             crop_x = (size_t)(new_width / 2.0 - width / 2.0);
         } 
     }
     MagickResetIterator(magick_wand);
     while (MagickNextImage(magick_wand) != MagickFalse) {
         MagickResizeImage(magick_wand,new_width,new_height,LanczosFilter,1.0);
         MagickCropImage(magick_wand,width,height,crop_x,crop_y);
     }
     
     width_ = width;
     height_ = height;
 }
Exemplo n.º 15
0
Object c_Gmagick::t_flattenimages() {
  INSTANCE_METHOD_INJECTION_BUILTIN(Gmagick, Gmagick::flattenimages);
  checkNotEmpty();
  MagickResetIterator(magick_wand);
  MagickWand *tmp_wand = MagickFlattenImages(magick_wand);

  if (tmp_wand == (MagickWand *)NULL) {
    throwException("Flatten images failed", ImageError);
  }

  DestroyMagickWand(magick_wand);
  magick_wand = tmp_wand;
  
  return this;
}
Exemplo n.º 16
0
static PyObject *
im_ResetIterator(PyObject *self, PyObject *args) {

	void *magick_pointer;
	MagickWand *magick_wand;

	if (!PyArg_ParseTuple(args, "O", &magick_pointer)){
		Py_INCREF(Py_None);
		return Py_None;
	}

	magick_wand = (MagickWand *) PyCObject_AsVoidPtr(magick_pointer);
	MagickResetIterator(magick_wand);

	Py_INCREF(Py_None);
	return Py_None;
}
Exemplo n.º 17
0
caddr_t bif_im_RotateImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  double v_size = bif_double_arg (qst, args, 1, "IM RotateImageFile");
  im_init (&env, qst, args, "IM RotateImageFile");
  im_env_set_filenames (&env, 0, 2);
  im_read (&env);
  im_set_background (&env, "#000000");
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickRotateImage (env.ime_magick_wand, env.ime_background, v_size);
  }
  im_write (&env);
  im_leave (&env);
  return (0);
}
int convert (MagickWand *input, MagickWand **output, convert_t *opts, unsigned char* data, size_t size) {
  if (convert_density(input, opts) != MagickPass) return -7;
  if (MagickReadImageBlob(input, data, size) != MagickPass) return -2;
  if (convert_adjoin(input, output, opts) != MagickPass) return -8;

  input = *output;

  MagickResetIterator(input);
  MagickNextImage(input); // Has to be called after MagickResetIterator to set the first picture as the current
  do {
    if (convert_format(input, opts) != MagickPass) return -3;
    if (convert_scale(input, opts) != MagickPass)  return -4;
    if (convert_rotate(input, opts) != MagickPass) return -5;
    if (convert_crop(input, opts) != MagickPass)   return -6;
  } while (MagickNextImage(input));
  return 0;
}
Exemplo n.º 19
0
// Returns the current image sequence as a string
String c_Gmagick::t_getimageblob() {
  INSTANCE_METHOD_INJECTION_BUILTIN(Gmagick, Gmagick::getimageblob);
  unsigned char * image_contents;
  size_t image_size;

  checkNotEmpty();
  checkHasFormat();

  MagickResetIterator(magick_wand);
  image_contents = MagickWriteImageBlob(magick_wand, &image_size);
  if (!image_contents) {
    return null;
  }    

  String ret((const char *)image_contents, image_size, CopyString);
  MagickRelinquishMemory(image_contents);
  return ret;
}
Exemplo n.º 20
0
caddr_t bif_im_CropImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  unsigned long width = (unsigned long) bif_long_arg (qst, args, 1, "IM CropImageFile");
  unsigned long height = (unsigned long) bif_long_arg (qst, args, 2, "IM CropImageFile");
  long x = bif_long_arg (qst, args, 3, "IM CropImageFile");
  long y = bif_long_arg (qst, args, 4, "IM CropImageFile");
  im_init (&env, qst, args, "IM CropImageFile");
  im_env_set_filenames (&env, 0, 5);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
  }
  im_write (&env);
  im_leave (&env);
  return (0);
}
Exemplo n.º 21
0
caddr_t bif_im_ThumbnailImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  long v_size = bif_long_arg (qst, args, 1, "IM ThumbnailImageFile");
  long h_size = bif_long_arg (qst, args, 2, "IM ThumbnailImageFile");
  long filter = bif_long_arg (qst, args, 3, "IM ThumbnailImageFile");
  im_init (&env, qst, args, "IM ThumbnailImageFile");
  im_env_set_filenames (&env, 0, 4);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,1.0);
    MagickProfileImage (env.ime_magick_wand, "*", NULL, 0);
  }
  im_write (&env);
  im_leave (&env);
  return(0);
}
Exemplo n.º 22
0
caddr_t bif_im_RotateImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  double v_size = bif_double_arg (qst, args, 2, "IM RotateImageBlob");
  im_init (&env, qst, args, "IM RotateImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 3, -1);
  im_read (&env);
  im_set_background (&env, "#000000");
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickRotateImage (env.ime_magick_wand, env.ime_background, v_size);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 23
0
int resize_image(char* path, char* req_path, size_t size, char* mode)
{
	// Create new image
	MagickWand* magick_wand = NewMagickWand();
	if((uintptr_t)magick_wand < 1)
		error("Could not initialize ImageMagick (magick_wand is NULL)", EXIT_FAILURE);

	// Read the Image
	bool status = MagickReadImage(magick_wand, path);
	if (status == false)
		return -1;

	size_t width = MagickGetImageWidth(magick_wand);
	size_t height = MagickGetImageHeight(magick_wand);

	// If the size is bigger than both height and width, redirect to original
	if(size >= width)
		return 1;

	size_t new_height = size;
	size_t new_width = size;

	// Unless a square image is requested, calculcate proper aspect ratio
	if(size != 1 && strcmp(mode, "square"))
		new_height = height * size / width;

	/* Turn the image into a thumbnail sequence (for animated GIFs)
	 * Automatically switches to a less cpu intense filter for animated GIFs.
	 */
	MagickResetIterator(magick_wand);
	for(int i = 0; MagickNextImage(magick_wand) != false && i < 250; i++)
		MagickResizeImage(magick_wand, new_width, new_height, !i ? LanczosFilter : TriangleFilter, 1);

	// Write the image
	status = MagickWriteImages(magick_wand, req_path, true);
	if (status == MagickFalse)
		error("Could not write image", EXIT_FAILURE)

	DestroyMagickWand(magick_wand);
	return 0;
}
Exemplo n.º 24
0
caddr_t 
bif_im_AnnotateImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  char * szMe = "IM AnnotateImageBlob";
  caddr_t res;
  caddr_t blob = (caddr_t)bif_arg (qst, args, 0, szMe);
  long blob_size = box_length (blob) - 1;
  long x_pos = bif_long_arg (qst, args, 1, szMe);
  long y_pos = bif_long_arg (qst, args, 2, szMe);
  caddr_t text = bif_string_arg (qst, args, 3, szMe);
  int n_args = BOX_ELEMENTS(args);
  long angle = n_args > 4 ? bif_long_arg (qst, args, 4, szMe) : 0;
  long f_size = n_args > 5 ? bif_long_arg (qst, args, 5, szMe) : 12;
  char *text_color = n_args > 6 ? bif_string_arg (qst, args, 6, szMe) : "black" ;
  dtp_t dtp = DV_TYPE_OF (blob);
  im_env_t env;
  im_init (&env, qst, args, "IM AnnotateImageBlob");
  if (IS_STRING_DTP (dtp))
    blob_size = box_length (blob) - 1;
  else if (dtp == DV_BIN)
    blob_size = box_length (blob);
  else
    im_leave_with_error (&env, "22023", "IM001", "AnnotateImageBlob needs string or binary as 1-st argument");
  im_env_set_blob_ext (&env, 7, -1);

  env.ime_drawing_wand = NewDrawingWand ();
  im_read (&env);
  im_set_background (&env, text_color);
  DrawSetFillColor (env.ime_drawing_wand, env.ime_background);
  DrawSetFontSize (env.ime_drawing_wand, f_size);
  MagickResetIterator  (env.ime_magick_wand);
  while (MagickNextImage  (env.ime_magick_wand) != MagickFalse)
    {
      env.ime_status = MagickAnnotateImage  (env.ime_magick_wand, env.ime_drawing_wand, x_pos, y_pos, angle, text);
      if (env.ime_status == MagickFalse)
        im_leave_with_error (&env, "22023", "IM001", "Cannot annotate image");
    }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 25
0
  char *get_thumbnail(char *full_filename, char *thumbnail_str, size_t *thumbnail_size)
 {
	
	char image_data = NULL;
	if(full_filename == NULL || thumbnail_str == NULL)
		return NULL;
	MagickBooleanType  status;
   	MagickWand  *magick_wand, *tmp_magick_wand;
	magick_wand=NewMagickWand();
	status=MagickReadImage(magick_wand, full_filename);
	if (status == MagickFalse)
  	  ThrowWandException(magick_wand);
	size_t height = MagickGetImageHeight(magick_wand);
	size_t width = MagickGetImageWidth(magick_wand);
	ssize_t i, j;
	ParseMetaGeometry(thumbnail_str, &i, &j, &width, &height);
	if(width <= 0 || height <= 0)
	{
		logError("%s%s:Geometry  %s error\n", __FILE__, __func__, thumbnail_str);
	}
	else
	{
		/*
		if(is_gif(full_filename))
		{
			  tmp_magick_wand = magick_wand;
			  magick_wand = MagickCoalesceImages(tmp_magick_wand);
			  tmp_magick_wand =   DestroyMagickWand(tmp_magick_wand);
		}
		*/	
		 MagickResetIterator(magick_wand);
   		 while (MagickNextImage(magick_wand) != MagickFalse)
     		 {
     		 	MagickThumbnailImage(magick_wand,height,width);
   		 }
		image_data =  MagickGetImagesBlob(magick_wand, thumbnail_size);
	}
	
	magick_wand=DestroyMagickWand(magick_wand);
	return image_data;
}
Exemplo n.º 26
0
caddr_t bif_im_ResizeImageFile (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  long v_size = bif_long_arg (qst, args, 1, "IM ResizeImageFile");
  long h_size = bif_long_arg (qst, args, 2, "IM ResizeImageFile");
  double blur = bif_double_arg (qst, args, 3, "IM ResizeImageFile");
  long filter = bif_long_arg (qst, args, 4, "IM ResizeImageFile");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ResiseImageFile");
  im_env_set_filenames (&env, 0, 5);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,blur);
  }
  im_write (&env);
  im_leave (&env);
  return(0);
}
Exemplo n.º 27
0
caddr_t bif_im_CropImageBlob(caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  unsigned long width = bif_long_arg (qst, args, 2, "IM CropImageBlob");
  unsigned long height = bif_long_arg (qst, args, 3, "IM CropImageBlob");
  long x = bif_long_arg (qst, args, 4, "IM CropImageBlob");
  long y = bif_long_arg (qst, args, 5, "IM CropImageBlob");
  im_init (&env, qst, args, "IM CropImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 6, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
	{
      MagickCropImage (env.ime_magick_wand, width, height, x, y);
	}
  res = im_write (&env);
  im_leave (&env);
  return res;
  }
Exemplo n.º 28
0
caddr_t bif_im_ResampleImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  double v_size = bif_double_arg (qst, args, 2, "IM ResampleImageBlob");
  double h_size = bif_double_arg (qst, args, 3, "IM ResampleImageBlob");
  double blur = bif_double_arg (qst, args, 4, "IM ResampleImageBlob");
  long filter = bif_long_arg (qst, args, 5, "IM ResampleImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ResampleImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 6, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
  {
    MagickResampleImage (env.ime_magick_wand,v_size, h_size,filter,blur);
  }
  res = im_write (&env);
  im_leave (&env);
  return res;
}
Exemplo n.º 29
0
 void fit(size_t width, size_t height)
 {
     double width_ratio = (double)width/width_;
     double height_ratio = (double)height/height_;
     size_t new_width, new_height;
     if(width_ratio < height_ratio)
     {
         new_width = width;
         new_height = (size_t)(height_ * width_ratio);
     }
     else
     {
         new_width = (size_t)(width_ * height_ratio);
         new_height = height;
     }
     width_ = new_width;
     height_ = new_height;
     
     MagickResetIterator(magick_wand);
     while (MagickNextImage(magick_wand) != MagickFalse) {
         MagickResizeImage(magick_wand,new_width,new_height,LanczosFilter,1.0);
     }
 }
Exemplo n.º 30
0
caddr_t bif_im_ThumbnailImageBlob (caddr_t * qst, caddr_t * err, state_slot_t ** args)
{
  im_env_t env;
  caddr_t res;
  long v_size = bif_long_arg (qst, args, 2, "IM ThumbnailImageBlob");
  long h_size = bif_long_arg (qst, args, 3, "IM ThumbnailImageBlob");
  long filter = bif_long_arg (qst, args, 4, "IM ThumbnailImageBlob");
  if (filter < 0 || filter > 15)
    filter = PointFilter;
  im_init (&env, qst, args, "IM ThumbnailImageBlob");
  im_env_set_input_blob (&env, 0);
  im_env_set_blob_ext (&env, 5, -1);
  im_read (&env);
  MagickResetIterator (env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
		{
    MagickResizeImage (env.ime_magick_wand,v_size, h_size,filter,1.0);
    MagickProfileImage (env.ime_magick_wand, "*", NULL, 0);
		}
  res = im_write (&env);
  im_leave (&env);
  return res;
	}