Subversion Repositories RepoView

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 nishi 1
/* $Id: magick.c 42 2024-08-22 05:25:09Z nishi $ */
2
 
3
#include "rv_magick.h"
4
 
5
#include "rv_util.h"
6
 
7
#include "../config.h"
8
 
9
#include <stdio.h>
10
#include <stdbool.h>
11
 
12
#include <wand/magick_wand.h>
13
 
14
void rv_init_magick(void) {}
15
 
16
bool rv_resize_picture(const char* input, const char* output, char** reason) {
17
	MagickWand* wand = NULL;
18
	wand = NewMagickWand();
19
	if(MagickReadImage(wand, input)) {
20
		int width = MagickGetImageWidth(wand);
21
		int height = MagickGetImageHeight(wand);
22
 
23
		double scale = 0;
24
		if(width >= height) {
25
			scale = (double)256 / width;
26
		} else if(width < height) {
27
			scale = (double)256 / height;
28
		}
29
 
30
		MagickResizeImage(wand, width * scale, height * scale, LanczosFilter, 1);
31
		MagickSetCompressionQuality(wand, 80);
32
		MagickWriteImage(wand, output);
33
 
34
		if(wand) DestroyMagickWand(wand);
35
		return true;
36
	}
37
	if(wand) DestroyMagickWand(wand);
38
	*reason = rv_strdup("Magick error");
39
	return false;
40
}