cvs: gd /playground/text_on_transparent_background text_aa_alpha.c

[email protected] ("Pierre-Alain Joye")
Newsgroups php.gd.cvs
Message-ID <cvspajoye1174157170@cvsserver>
pajoye		Sat Mar 17 18:46:10 2007 UTC

  Added files:                 
    /gd/playground/text_on_transparent_background	text_aa_alpha.c 
  Log:
  - example of antialiased text using alpha and not blending ops
  
  

http://cvs.php.net/viewvc.cgi/gd/playground/text_on_transparent_background/text_aa_alpha.c?view=markup&rev=1.1
Index: gd/playground/text_on_transparent_background/text_aa_alpha.c
+++ gd/playground/text_on_transparent_background/text_aa_alpha.c
#include <gd.h>
#include <stdio.h>
#include <math.h>

int main()
{
	gdImagePtr im, tmp_im;
	int error = 0;
	char *fontname = "/var/lib/defoma/fontconfig.d/B/Bitstream-Vera-Sans.ttf";
	char *string = "AA using alpha";
	int linespacing	= 1.05;
	int charmap    	= gdFTEX_Unicode;
	int resolution		= 96;
	int color_text 	= 0xFFFFFF;
	int pt_size 		= 50;
	double angle 		= -45 * M_PI / 180;
	int pos_x = 0, pos_y = 40;
	FILE *fp;
	gdFTStringExtra extra;

	/* Optional but it makes the code clearer and forward compatible */
	extra.flags = gdFTEX_CHARMAP|gdFTEX_RESOLUTION;
	extra.charmap = gdFTEX_Unicode;
	extra.hdpi = resolution;
	extra.vdpi = resolution;

	im = gdImageCreateTrueColor(400,400);

	/* We want to presereve the alpha information, don't blend */
	gdImageAlphaBlending(im, 0);

	/* let fill it with zero opacity (gdMaxAlphaMax) */
	gdImageFilledRectangle(im, 0,0, 399,399, gdImageColorAllocateAlpha(im, 0,0,0, gdAlphaMax));
	gdImageStringFTEx(im, NULL, color_text, fontname, pt_size, angle, pos_x, pos_y, string, &extra);

	/* Save the alpha channel in the image, that disallows the usage
		of a background/transparent color. See PNG specs for the details.
	 */
 	gdImageSaveAlpha(im, 1);
	fp = fopen("1.png", "wb");
 	gdImagePng(im,fp);
	fclose(fp);

 	/* Destroy images */
 	gdImageDestroy(im);
	return error;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.