~jkaivo/freeonebook

ref: 6d5b39e764a89e039d8bddddfde9f3730e3a7af5 freeonebook/convert.c -rw-r--r-- 712 bytes
6d5b39e7 — Jakob Kaivo properly loading a PNG from disk 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
#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();
		w = NewMagickWand();
		pixel = NewPixelWand();
	}

	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;
}