gd_write . gd . sncode
latest
Write a GD image to a file or send it to the client.
GD_WRITE(1e)
NAME
gd_write - Writes a GD image to a file or sends it to the client.
SYNOPSIS
gd_write (gd:variable, filename:"string", format:"string", base64: boolean, bgcolor:"string",quality:integer);
DESCRIPTION
This function is used to write a GD image to a file or send it to the client.
If no filename is specified, output goes to the client or stdout if not with apache.
PARAMETERS
- filename
- Specifyies the initial filename to write.
- base64
- If base64 is true and filename is specified, gd_write will return an image as a base64 encoding
- bgcolor
- Specifies background color. A color is specified as "#XXXXX" or as "255,255,255".
- format
- Format of the file. This can be gif, jpg, png, gd, gd2, wbmp, xbm, xpm.
- gd
- Variable must hold a returned value from gd_new.
- quality
- Quality of image. If quality is negative, the default quality value (which should yield a good general quality / size tradeoff for most situations) is used. Otherwise, for practical purposes, quality should be a value in the range 0-95, higher quality values usually implying both higher quality and larger image sizes.
RETURN
- Nothing. Null.
MODULES
To use this module, you must specify the following in /usr/local/website/site.conf:
Module gd { Library : "/usr/local/lib/libsngd.so" Init : "sngd_init" }
EXAMPLES
Note: In the followings examples, the _ between the { should be removed to make it work.
{_{ %include "/includes/gd.sn"; // Prepare constants vowels = "AEIOUY"; lenvoyels = vowels.length()-1; others = "BCDFGHJKLMNPQRSTVWXZ"; lenothers = others.length()-1; numbers = "0123456789"; font = ["/ttf/bignoodle.ttf","/ttf/vera.ttf","/ttf/FRABKIT.ttf","/ttf/arial.ttf", "/ttf/FRAMDIT.ttf"]; // Generate image im=gd_new(width:200,height:80,bgcolor:Gray,truecolor:true); fgcolor = gd_get_color(gd:im, color:White); // Generate random text str = ""; x = 8; length=10; fontlen = font.length(); f=random(min:0,max:fontlen-1); f; for(i=1;i<=length;++i) do angle=random(min:5,max:20); size=random(min:12,max:14); pos=random(min:15,max:20); if i % 2 == 0 then n = random(min:0,max:lenvoyels); c = strsub(start:n,finish:n,vowels); str .+= c; else n = random(min:0,max:lenothers); c = strsub(start:n,finish:n,others); str .+= c; endif r = gd_print(gd:im,font:font[f],angle:angle,x:x,y:pos,size:size,coloridx:fgcolor,str:c); x += 12; endfor "<p>"; str; '</p>'; d = datetime(); r = gd_print(gd:im,font:"/ttf/arial.ttf",x:10,y:50,size:14,coloridx:fgcolor,str:d); red = gd_get_color(gd:im, color:Red); cyan = gd_get_color(gd:im, color:Cyan); white = gd_get_color(gd:im, color:White); yellow = gd_get_color(gd:im, color:Yellow); a=gd_write(gd:im,format:"png",base64:true,quality:100); b=gd_write(gd:im,format:"gif",base64:true,quality:100); c=gd_write(gd:im,format:"jpg",base64:true,quality:100); gd_write(gd:im,format:"jpg",filename:"/extenso/html/img.jpg",quality:100); gd_free(gd:im); }} PNG <img src=""> <br /> <hr> GIF <img src=""> <br /> <hr> JPG <img src=""> <br /> <hr> JPGFILE <img src="/extenso/img.jpg"> <br /> <hr> </body>
AUTHOR
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>