gd_write - Writes a GD image to a file or sends it to the client.
gd_write (gd:variable, filename:"string", format:"string", base64: boolean, bgcolor:"string",quality:integer);
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.
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" }
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="{{a}}"> <br /> <hr> GIF <img src="{{b}}"> <br /> <hr> JPG <img src="{{c}}"> <br /> <hr> JPGFILE <img src="/extenso/img.jpg"> <br /> <hr> </body>
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
1.0 2014-09-09 21:24:14 laplante@sednove.com