5
#define DEG2RAD(x) ((x)*PI/180.)
7
#define MAX(x,y) ((x) > (y) ? (x) : (y))
8
#define MIN(x,y) ((x) < (y) ? (x) : (y))
10
#define MAX4(x,y,z,w) \
11
((MAX((x),(y))) > (MAX((z),(w))) ? (MAX((x),(y))) : (MAX((z),(w))))
12
#define MIN4(x,y,z,w) \
13
((MIN((x),(y))) < (MIN((z),(w))) ? (MIN((x),(y))) : (MIN((z),(w))))
15
#define MAXX(x) MAX4(x[0],x[2],x[4],x[6])
16
#define MINX(x) MIN4(x[0],x[2],x[4],x[6])
17
#define MAXY(x) MAX4(x[1],x[3],x[5],x[7])
18
#define MINY(x) MIN4(x[1],x[3],x[5],x[7])
20
int main(int argc, char *argv[])
23
fprintf(stderr, "gd was not compiled with HAVE_LIBTTF defined.\n");
24
fprintf(stderr, "Install the FreeType library, including the\n");
25
fprintf(stderr, "header files. Then edit the gd Makefile, type\n");
26
fprintf(stderr, "make clean, and type make again.\n");
37
char *s = "Hello. ����ɂ��� Qyjpqg,"; /* String to draw. */
39
char *s = "Hello. Qyjpqg,"; /* String to draw. */
42
double angle = DEG2RAD(-90);
44
char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf"; /* UNICODE */
45
/* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; */ /* SJIS */
47
char *f = "/usr/local/lib/fonts/truetype/misc/times.ttf"; /* TrueType font */
50
/* obtain brect so that we can size the image */
51
err = gdImageStringTTF((gdImagePtr)NULL,&brect[0],0,f,sz,angle,0,0,s);
52
if (err) {fprintf(stderr,err); return 1;}
54
/* create an image just big enough for the string */
55
x = MAXX(brect) - MINX(brect) + 6;
56
y = MAXY(brect) - MINY(brect) + 6;
57
im = gdImageCreate(x,y);
59
/* Background color (first allocated) */
60
white = gdImageColorResolve(im, 255, 255, 255);
61
black = gdImageColorResolve(im, 0, 0, 0);
63
/* render the string, offset origin to center string*/
64
x = 0 - MINX(brect) + 3;
65
y = 0 - MINY(brect) + 3;
66
err = gdImageStringTTF(im,&brect[0],black,f,sz,angle,x,y,s);
67
if (err) {fprintf(stderr,err); return 1;}
69
/* Write img to stdout */
70
gdImagePng(im, stdout);