• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

ImageMagick MagickAutoOrientImage

互联网 diligentman 1周前 (11-19) 6次浏览

最近在用imageMagick 进行图像处理,主要是lua ffi调用ImageMagick, 发现MagickAutoOrientImage在旧版本中不存在,目前可以确定的是这个函数在ImageMagick 6.8.9中才出现。

WandExport MagickBooleanType MagickAutoOrientImage(MagickWand *wand)
{

  Image
    *orient_image;

  assert(wand != (MagickWand *) NULL);
  assert(wand->signature == WandSignature);
  if (wand->debug != MagickFalse)
    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
  if (wand->images == (Image *) NULL)
    ThrowWandException(WandError,"ContainsNoImages",wand->name);
  orient_image=AutoOrientImage(wand->images,wand->images->orientation,
    wand->exception);
  if (orient_image == (Image *) NULL)
    return(MagickFalse);
  ReplaceImageInList(&wand->images,orient_image);
  return(MagickTrue);
}

所以就要看AutoOrientImage的实现来手动实现

MagickExport Image *AutoOrientImage(const Image *image,
  const OrientationType orientation,ExceptionInfo *exception)
{
  Image
    *orient_image;

  assert(image != (const Image *) NULL);
  assert(image->signature == MagickSignature);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);
  orient_image=(Image *) NULL;
  switch(orientation)
  {
    case UndefinedOrientation:
    case TopLeftOrientation:
    default:
    {
      orient_image=CloneImage(image,0,0,MagickTrue,exception);
      break;
    }
    case TopRightOrientation:
    {
      orient_image=FlopImage(image,exception);
      break;
    }
    case BottomRightOrientation:
    {
      orient_image=RotateImage(image,180.0,exception);
      break;
    }
    case BottomLeftOrientation:
    {
      orient_image=FlipImage(image,exception);
      break;
    }
    case LeftTopOrientation:
    {
      orient_image=TransposeImage(image,exception);
      break;
    }
    case RightTopOrientation:
    {
      orient_image=RotateImage(image,90.0,exception);
      break;
    }
    case RightBottomOrientation:
    {
      orient_image=TransverseImage(image,exception);
      break;
    }
    case LeftBottomOrientation:
    {
      orient_image=RotateImage(image,270.0,exception);
      break;
    }
  }
  if (orient_image != (Image *) NULL)
    orient_image->orientation=TopLeftOrientation;
  return(orient_image);
}

 


程序员灯塔
转载请注明原文链接:https://www.wangt.cc/2020/11/imagemagick-magickautoorientimage/
喜欢 (0)