in reply to Dymanically Generated Images in Website
Dude.. make one scripts like image.cgi which spits out the image and your html.cgi or any html will call it like <img src="/cgi-bin/image.cgi?yup">
do some testing with the image.cgi first via htp see if it does what you want
here.. i made this script that spits out text to screen.. You just have to tweak where on your server the ttf file is .. etc. This script is not fully complete.. but.. it works!
#!/usr/bin/perl -wT use strict; use Image::Magick; use CGI; my $conf = { font_size => 8, font_name=>'/srv/www/htdocs-devel/lib/kroe0555.ttf', img_type=>'png', }; my $t = new CGI(); my $string = $t->param('string'); $string ||='leocharre'; $$conf{string} = untaint( $string ); # attempt untaint $$conf{img_height} = int($$conf{font_size}*1.33) ; $$conf{img_width} = ( length($$conf{string}) * int($$conf{font_size}*0 +.8) ); my $bgcolor = $t->param('bgcolor'); my $fgcolor = $t->param('fgcolor'); $bgcolor ||='#fff'; $fgcolor ||='#000'; $$conf{bgcolor} = untaint_color($bgcolor); $$conf{fgcolor} = untaint_color($fgcolor); generate_img($conf); show_and_exit($conf); sub show_and_exit { my $conf = shift; # read in image and output to browser print(qq|Content-Type: image/$$conf{img_type}\n\n|); binmode STDOUT; $$conf{img}->Write($$conf{img_type}.':-'); exit; } sub generate_img{ my $conf = shift; $$conf{img} = Image::Magick->new; $$conf{img}->Set(size => $$conf{img_width}."x".$$conf{img_height}) +; $$conf{img}->ReadImage('xc:'.$$conf{bgcolor}); $$conf{img}->Annotate( font=> $$conf{font_name}, pointsize=> $$conf{font_size}, fill=> $$conf{fgcolor}, text=> $$conf{string}, gravity=> 'center' ); } sub untaint { my $string= shift; if ($string=~/^([a-zA-Z0-9 \.\:\[\]\{\}\+\-_]+)$/){ return $1; } die ("don't like some chars here = [$string]"); } sub untaint_color { my $color = shift; if ($color=~/^([\d\w#]{3,7})$/){ return $1; } die ("the heck kind of color is this? [$color]"); }
|
|---|