diff options
Diffstat (limited to 'convert.c')
| -rw-r--r-- | convert.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/convert.c b/convert.c new file mode 100644 index 0000000..333d79d --- /dev/null +++ b/convert.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <string.h> + +#define MAGICKCORE_QUANTUM_DEPTH 8 +#define MAGICKCORE_HDRI_ENABLE 0 +#include <MagickCore/MagickCore.h> + +int convert(const char *in, const char *out, int width, int height) +{ + if (!IsMagickCoreInstantiated()) { + MagickCoreGenesis(NULL, MagickFalse); + } + + printf("converting image %s\n", in); + + ExceptionInfo *exception = AcquireExceptionInfo(); + + printf("reading original image\n"); + ImageInfo *info = CloneImageInfo((ImageInfo*)NULL); + if (info == NULL) { + printf("couldn't create new ImageInfo\n"); + return 1; + } + strcpy(info->filename, in); + Image *original = ReadImage(info, exception); + if (original == NULL) { + printf("couldn't read original\n"); + return 0; + } + + printf("resizing\n"); + Image *resized = ResizeImage(original, width, height, LanczosFilter, exception); + DestroyImage(original); + if (resized == NULL) { + printf("couldn't resize\n"); + return 0; + } + + printf("rotating\n"); + Image *rotated = IntegralRotateImage(resized, 3, exception); + DestroyImage(resized); + if (rotated == NULL) { + printf("couldn't rotate\n"); + return 0; + } + + printf("writing grayscale\n"); + strcpy(info->filename, out); + WriteImage(info, rotated, exception); + + printf("cleaning up\n"); + DestroyImage(rotated); + DestroyImageInfo(info); + DestroyExceptionInfo(exception); + + return 1; +} |
