~jkaivo/freeonebook

ref: e791b3713a8e9932e48dcb141275d11acc199538 freeonebook/convert.c -rw-r--r-- 921 bytes
e791b371 — Jakob Kaivo more error checking 3 years ago
                                                                                
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;
}