View and vote on the article here: Chef's Recipe
Chef's Recipe| Category | | | Summary | | Today, we'll learn how to cook something pleasing to the eyes. |
| | Body | We need: 5.8 grams of perl, between 1.3 and 2.x kg of apache and a perl module called "GD" for decoration (including the -dev libraries for it).
How we prepare:
Take perl and clean it this way:
# cpan
or
# perl -MCPAN -e shell
We wash GD:
cpan> install GD
Then we take apache and slice it by adding this to httpd.conf:
<IfModule mod_perl.c>
PerlRequire /var/www/perl/startup.pl
<IfModule mod_alias.c>
Alias /perl/ /var/www/perl/
</IfModule>
<Location /perl>
SetHandler cgi-script
PerlHandler Apache::Registry
Options +ExecCGI
</Location>
</IfModule>
I assume that you are using the default /var/www/ kind of flavor and that you want to cook your meal in the /perl.
To speed up the cooking process, you need to create startup.pl and fill
use strict;
$ENV{MOD_PERL} or die "not running under mod_perl!";
use Apache::Registry ( );
use GD ( );
use File::Random ( );
use Time::HiRes ( );
1;
it with the above and place it in /var/www/startup.pl .
Now, we arrived to the most important part: we need to cook our meal.
we open the oven and prewarm it:
# cd /var/www/perl;touch script.pl
and we put the ingredients into the put the roast pan:
# nano -w script.pl
(Of course, other roast pans can be used as well, like vim, emacs, pico, joe or grandma's favorite, and some claim they get better results using those.)
We put the ingredients in the pan:
#!/usr/bin/perl
use strict;
use Time::HiRes;
use File::Random qw/random_line/;
use GD;
my $start = Time::HiRes::time();
#here we load a random line from our quotes db.
my $line = random_line("quotes.txt");
rand($.) < 1 && ($line = $_) while <>;
$line =~ s/\\n//g;
#here we specify content-type
print "Content-type: image/png\\n\\n";
#here we create a new custom sized image (length of the quote)
my $im = new GD::Image(length($line)*6+45,40);
#here we create the basic colors used/available
my $black = $im->colorAllocate(0,0,0);
my $white = $im->colorAllocate(255,255,255);
my $cabg = $im->colorAllocate(38,60,109);
my $casos = $im->colorAllocate(255,215,0);
my $casas = $im->colorAllocate(111,125,255);
# make the background transparent and interlaced
$im->transparent($white);
$im->interlaced('true');
# we fill the image with the CyberArmy background color
$im->filledRectangle(0,0,length($line)*7+45,40,$cabg);
# we display our string here
$im->string(gdMediumBoldFont,2,2,"Quote: ",$casas);$im->string(gdSmallFont,45,2,$line,$casas);
# make sure we are writing to a binary stream
my $time = sprintf('%.5f',Time::HiRes::time - $start);
$im->string(gdTinyFont,2,20,$time."s",$casos);
binmode STDOUT;
print $im->png;
exit 0;
and voila:
The meal is ready for human consumption!
If someone would like to create more advanced dishes with the great spice called GD, they can find some help here. |
|
This article was imported from zZine. (original author: comet)
There are no replies to this post yet.
|