summaryrefslogtreecommitdiff
path: root/convert.c
blob: 1afafd02130cfaa39933e58f5843debf1b38d0ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <string.h>

#include <MagickWand/MagickWand.h>

int convert(const char *in, const char *out, int width, int height)
{
	static MagickWand *w = NULL;
	static PixelWand *pixel = NULL;

	if (!IsMagickWandInstantiated()) {
		MagickWandGenesis();
	}

	if (w == NULL) {
		w = NewMagickWand();
		if (w == NULL) {
			printf("couldn't create MagickWand\n");
			return 1;
		}
	}

	if (pixel == NULL) {
		pixel = NewPixelWand();
		if (pixel == NULL) {
			printf("couldn't create PixelWand\n");
			return 1;
		}
	}

	if (!MagickReadImage(w, in)) {
		printf("couldn't read '%s'\n", in);
		return 1;
	}

	if (!MagickAdaptiveResizeImage(w, width, height)) {
		printf("couldn't resize image\n");
		return 1;
	}

	if (!MagickRotateImage(w, pixel, 270)) {
		printf("couldn't rotate image\n");
		return 1;
	}

	if (!MagickWriteImage(w, out)) {
		printf("couldn't write '%s'\n", out);
		return 1;
	}

	return 0;
}