int convert_rotate (MagickWand *input, convert_t *opts) {
  if (!opts->rotate_degrees) return MagickPass;
  if (opts->rotate_degrees == 360) opts->rotate_degrees = 0;

  char* exif_orientation = MagickGetImageAttribute(input,  "EXIF:Orientation");

  if (exif_orientation != NULL) {
    switch (atoi(exif_orientation)) {
      case 3:
      opts->rotate_degrees += 180;
      break;

      case 6:
      opts->rotate_degrees += 90;
      break;

      case 8:
      opts->rotate_degrees += 270;
      break;
    }

    // just clear all exif data
    MagickProfileImage(input, "exif", NULL, 0);
  }

  return opts->rotate_degrees ? MagickRotateImage(input, default_background, opts->rotate_degrees) : MagickPass;
}
Пример #2
0
caddr_t
bif_im_get_impl (caddr_t * qst, caddr_t * err, state_slot_t ** args, int is_file_in, int op, const char *bifname)
  {
  im_env_t env;
  char *strg_value = NULL;
  unsigned long ul_value = 0;
  caddr_t res = NULL;
  int is_string_res = (('A' == op) || ('F' == op) || ('I' == op));
  int is_list_res = ('2' == op);
  int is_key_needed = ('A' == op);
  caddr_t key = is_key_needed ? bif_string_arg (qst, args, (is_file_in ? 1 : 2), bifname) : NULL;
  im_init (&env, qst, args, bifname);
  if (is_file_in)
    im_env_set_filenames (&env, 0, -1);
  else
{
      im_env_set_input_blob (&env, 0);
      im_env_set_blob_ext (&env, (is_key_needed ? 3 : 2), -1);
    }
  im_read (&env);
  MagickResetIterator(env.ime_magick_wand);
  while (MagickNextImage (env.ime_magick_wand) != MagickFalse)
	{
      switch (op)
		{
        case 'A': strg_value = MagickGetImageAttribute (env.ime_magick_wand, key); break;
        case 'F': strg_value = MagickGetImageFormat (env.ime_magick_wand); break;
        case 'I': strg_value = MagickIdentifyImage (env.ime_magick_wand); break;
        case 'W': ul_value = MagickGetImageWidth (env.ime_magick_wand); break;
        case 'H': ul_value = MagickGetImageHeight (env.ime_magick_wand); break;
        case 'D': ul_value = MagickGetImageDepth (env.ime_magick_wand); break;
        case '2':
          ul_value = MagickGetImageWidth (env.ime_magick_wand);
          if (ul_value)
  {
              dk_free_tree (res);
              res = dk_alloc_box (2 * sizeof (caddr_t), DV_ARRAY_OF_POINTER);
              ((caddr_t *)res)[0] = box_num (ul_value);
              ((caddr_t *)res)[1] = box_num (MagickGetImageHeight (env.ime_magick_wand));
  }
          break;
  }
}
  if (is_string_res)
	{
      if (strg_value)
		{
          res = box_dv_short_string (strg_value);
          MagickRelinquishMemory (strg_value);
		}
	}
  else if (!is_list_res)
  {
      if (ul_value)
        res = box_num (ul_value);
  }
  if (NULL == res)
    res = NEW_DB_NULL;
  im_leave (&env);
  return res;
}