1 /*
2  *  Name:         Graphics functions
3  *
4  *  Purpose:      All the functions that are used to create the Online Signature Image
5  *
6  *  Author:       Pedro de Oliveira <falso@rdk.homeip.net>
7  *
8  *  Copyright (c) 2004-2011 Pedro de Oliveira ( falso@rdk.homeip-net )
9  *
10  *  This file is part of aMule.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the
24  *  Free Software Foundation, Inc.,
25  *  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA
26 */
27 
28 
29 #ifdef __GD__
30 
31 #include <stdlib.h>
32 
33 #include <gd.h>
34 
35 #include "functions.h"
36 #include "configfile.h"
37 #include "graphics.h"
38 
39 /*
40  * this is the funcion that writes the text to the image.
41  * almost everything is taken from libgd examples
42  */
43 int createimage(CONF *config, char *lines[IMG_TEXTLINES], char *path_for_picture)
44 {
45 	FILE *in, *out;
46 	char *path;
47 	gdImagePtr im;
48 	int white, i;
49 	int brect[8];
50 
51 	if ( (in = fopen(config->font, "r")) == NULL) {
52 		perror("font not found\ncheck casrc\n");
53 		return 0;
54 	}
55 	fclose(in);
56 
57 	if ( (in = fopen(config->source, "rb")) == NULL) {
58 		perror("source_image not found\ncheck casrc\n");
59 		return 0;
60 	}
61 
62 	im = gdImageCreateFromPng(in);
63 	fclose(in);
64 
65 	if( NULL == im) {
66 		perror("Error loading source image (not a valid png image file?).\n");
67 		return 0;
68 	}
69 	white = gdImageColorResolve(im, 255, 255, 255);
70 
71 	for (i = 0; i < IMG_TEXTLINES; i++) {
72 		if (config->enabled[i] == 1) {
73 			gdImageStringFT(im, &brect[0], white, config->font, config->size,
74 					0.0, config->x[i], config->y[i], lines[i]);
75 		}
76 	}
77 
78 	if (config->img_type==0) {
79 		path = get_amule_path("aMule-online-sign.png", 0, path_for_picture);
80 	} else {
81 		path = get_amule_path("aMule-online-sign.jpg", 0, path_for_picture);
82 	}
83 
84 	if (path == NULL && config->img_type==0) {
85 		perror("could not get PNG path\n");
86 		return 0;
87 	} else if (path == NULL) {
88 		perror("could not get JPG path\n");
89 		return 0;
90 	}
91 	out = fopen(path, "w");
92 	free(path);
93 
94 	if (config->img_type==0) {
95 		gdImagePng(im, out);
96 	} else {
97 		gdImageJpeg(im, out, -1);
98 	}
99 
100 	fclose(out);
101 	printf("Online Signature picture created.\n");
102 	gdImageDestroy(im);
103 
104 	return 1;
105 }
106 
107 #endif
108 
109