Skip to content

Instantly share code, notes, and snippets.

@koonix
Created September 10, 2022 21:15
Show Gist options
  • Save koonix/da3cd04cb3a82bde8c97e2a1506bd42f to your computer and use it in GitHub Desktop.
Save koonix/da3cd04cb3a82bde8c97e2a1506bd42f to your computer and use it in GitHub Desktop.
Bare minimal test of a direct call to ImageMagick library's ConvertImageCommand().
/* source: https://legacy.imagemagick.org/discourse-server/viewtopic.php?p=80803#p80803
* requires the "opencl-headers" package
* compile:
* cc ConvertExample.c -o convert $(pkg-config --libs --cflags MagickCore MagickWand) */
/*
Bare minimal test of a direct call to ConvertImageCommand()
Actually this is basically what the "convert" command does.
Compile with...
gcc -I`pwd` -lMagickWand -lMagickCore convert_equiv.c -o convert_equiv
*/
#include <stdio.h>
#include "ImageMagick-7/MagickCore/studio.h"
#include "ImageMagick-7/MagickCore/exception.h"
#include "ImageMagick-7/MagickCore/image.h"
#include "ImageMagick-7/MagickWand/MagickWand.h"
#include "ImageMagick-7/MagickWand/convert.h"
int main(int argc, char **argv)
{
MagickCoreGenesis(argv[0],MagickFalse);
char *args[] = { "convert", "-size", "100x100", "xc:red", "show:" };
int args_count = 5;
ImageInfo *image_info = AcquireImageInfo();
ExceptionInfo *exception = AcquireExceptionInfo();
MagickBooleanType status = ConvertImageCommand(image_info, args_count, args, NULL, exception);
if (exception->severity != UndefinedException) {
status=MagickTrue;
CatchException(exception);
}
/* this should not be needed as error is reported as an exception */
if (status == MagickFalse)
fprintf(stderr, "Error in call\n");
image_info=DestroyImageInfo(image_info);
exception=DestroyExceptionInfo(exception);
MagickCoreTerminus();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment