int main(int argc, char *argv[])
{
#ifndef HAVE_LIBTTF
	fprintf(stderr, "gd was not compiled with HAVE_LIBTTF defined.\n");
	fprintf(stderr, "Install the FreeType library, including the\n");
	fprintf(stderr, "header files. Then edit the gd Makefile, type\n");
	fprintf(stderr, "make clean, and type make again.\n");
	return 1;
#else
	gdImagePtr im;
	int black;
	int white;
	int brect[8];
	int x, y;
	char *err;

#ifdef JISX0208
	char *s = "Hello. こんにちは Qyjpqg,"; /* String to draw. */
#else
	char *s = "Hello. Qyjpqg,"; /* String to draw. */
#endif
	double sz = 40.;
	double angle = DEG2RAD(-90);
#ifdef JISX0208
	char *f = "/usr/openwin/lib/locale/ja/X11/fonts/TT/HG-MinchoL.ttf"; /* UNICODE */
	/* char *f = "/usr/local/lib/fonts/truetype/DynaFont/dfpop1.ttf"; */ /* SJIS */
#else
	char *f = "/usr/local/lib/fonts/truetype/misc/times.ttf"; /* TrueType font */
#endif
	
	/* obtain brect so that we can size the image */
	err = gdImageStringTTF((gdImagePtr)NULL,&brect[0],0,f,sz,angle,0,0,s);
	if (err) {fprintf(stderr,err); return 1;}

	/* create an image just big enough for the string */
	x = MAXX(brect) - MINX(brect) + 6;
	y = MAXY(brect) - MINY(brect) + 6;
	im = gdImageCreate(x,y);

	/* Background color (first allocated) */
	white = gdImageColorResolve(im, 255, 255, 255);
	black = gdImageColorResolve(im, 0, 0, 0);

	/* render the string, offset origin to center string*/
	x = 0 - MINX(brect) + 3;
	y = 0 - MINY(brect) + 3;
	err = gdImageStringTTF(im,&brect[0],black,f,sz,angle,x,y,s);
	if (err) {fprintf(stderr,err); return 1;}

	/* Write img to stdout */
	gdImagePng(im, stdout);

	/* Destroy it */
	gdImageDestroy(im);

	return 0;
#endif /* HAVE_TTF */
}	
Exemplo n.º 2
0
void
dosizes (gdImagePtr im, int color, char *fontfile,
	 int x, int y, const char *string)
{
  int brect[8];
  double curang = 0.0;
  char *cp;
  int cursize;
  char buf[60];

  for (cursize = 1; cursize <= 20; cursize++)
    {
      sprintf (buf, "%d: %s", cursize, string);

      /* The case of newlines is taken care of in the gdImageStringTTF call */
#if defined(OLDER_GD)
      cp =
	gdImageStringTTF (im, brect, color, fontfile, cursize, curang, x, y,
			  buf);
#else
      cp =
	gdImageStringFT (im, brect, color, fontfile, cursize, curang, x, y,
			 buf);
#endif
      if (cp)
	fprintf (stderr, "%s\n", cp);
      y += cursize + 4;

/* render the same fontsize with antialiasing turned off */
#if defined(OLDER_GD)
      cp =
	gdImageStringTTF (im, brect, 0 - color, fontfile, cursize, curang, x,
			  y, buf);
#else
      cp =
	gdImageStringFT (im, brect, 0 - color, fontfile, cursize, curang, x,
			 y, buf);
#endif
      if (cp)
	fprintf (stderr, "%s\n", cp);
      y += cursize + 4;
    }
}
Exemplo n.º 3
0
void
dowheel (gdImagePtr im, int color, char *fontfile, int fontsize,
         double angle, int x, int y, int offset, char *string)
{
	int brect[8];
	FILE *err;
	double curangrads, curang, x0, y0;
	char *cp;

	err = fopen ("err.out", "a");
	doerr (err, "------------- New fontwheel --------------");
	doerr (err, fontfile);
	doerr (err, string);
	doerr (err, "------------------------------------------");

	for (curang = 0.0; curang < 360.0; curang += angle) {
		curangrads = DEGTORAD(curang);
		x0 = x + cos (curangrads) * offset;
		y0 = y - sin (curangrads) * offset;

		/* The case of newlines is taken care of in the gdImageStringTTF call */
#if defined(OLDER_GD)
		cp = gdImageStringTTF (im, brect, color, fontfile, fontsize,
		                       curangrads, x0, y0, string);
#else
		cp = gdImageStringFT (im, brect, color, fontfile, fontsize,
		                      curangrads, x0, y0, string);
#endif
		if (cp)
			doerr (err, cp);

		gdImagePolygon (im, (gdPointPtr)brect, 4, color);
	}

	fclose (err);
}
Exemplo n.º 4
0
int main()
{
	gdImagePtr im;
	int black;
	int white;
	int brect[8];
	int x, y;
	char *err;

	char s[5];	/* String to draw. */
	double sz = 40.;
	char fontpath[256];
	unsigned int r;
	char buf[50];
	char userid[IDLEN + 1];
	struct MD5Context mdc;
	unsigned int pass[4];
	if (initbbsinfo(&bbsinfo) < 0)
		return -1;
	bzero(pass, sizeof(pass));
	strsncpy(buf, getsenv("QUERY_STRING"), sizeof (buf));
	__unhcode(buf);
	if (strncmp(buf, "userid=", 7)) {
		userid[0] = 0;
	} else {
		strsncpy(userid, buf+7, IDLEN+1);
	//	errlog("%s",userid);
	}
	if (userid[0] == 0) {
		s[0] = 0;
	} else {
		MD5Init(&mdc);
		MD5Update(&mdc, (void *)(&bbsinfo.ucachehashshm->regkey), sizeof(int) * 4);
		MD5Update(&mdc, userid, strlen(userid));
		MD5Final((char *)pass, &mdc);
		sprintf(s, "%d%d%d%d", pass[0]%10, pass[1] % 10, pass[2] % 10, pass[3] % 10);
	}
	getrandomint(&r);
	sprintf(fontpath, MY_BBS_HOME "/etc/fonts/%d.ttf", r % MAXFONTS);	/* User supplied font */

	fprintf(stdout, "Content-type: image/png\r\n\r\n");
/* obtain brect so that we can size the image */
	err = gdImageStringTTF(NULL, &brect[0], 0, fontpath, sz, 0., 0, 0, s);
	if (err) {
		return 1;
	}
/* create an image big enough for the string plus a little whitespace */
	x = brect[2] - brect[6] + 6;
	y = brect[3] - brect[7] + 6;
	im = gdImageCreate(x, y);

/* Background color (first allocated) */
	white = gdImageColorResolve(im, 255, 255, 255);
	black = gdImageColorResolve(im, 0, 0, 0);

/* render the string, offset origin to center string*/
/* note that we use top-left coordinate for adjustment
 * since gd origin is in top-left with y increasing downwards. */
	x = 3 - brect[6];
	y = 3 - brect[7];
	err = gdImageStringFT(im, &brect[0], black, fontpath, sz, 0.0, x, y, s);
	if (err) {
		return 1;
	}
/* Write img to stdout */
	gdImagePng(im, stdout);

/* Destroy it */
	gdImageDestroy(im);
	return 0;
}