cvs: gd /playground/text_on_transparent_background text_aa_alpha.c

From: Date: Sat, 17 Mar 2007 18:46:10 +0000
Subject: cvs: gd /playground/text_on_transparent_background text_aa_alpha.c
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-155@lists.php.net to get a copy of this message
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; }

« previous php.gd.cvs (#155) next »