Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: A new type of quote script

by PodMaster (Abbot)
on Oct 03, 2002 at 10:44 UTC ( #202473=note: print w/replies, xml ) Need Help??


in reply to A new type of quote script

I wrote one too (once upon a time) whilst learning about GD, but I was just reading off *DATA
#!C:/perl/bin/perl #!/usr/bin/perl BEGIN { unless( -t STDIN){ # if run on commandline, none of this require CGI::Carp; CGI::Carp::carpout(\*LOGGY) if open(LOGGY,'>>'.__FILE__.'.err.log'); CGI::Carp->import( 'fatalsToBrowser' ); } } use strict; use warnings; use GD; use constant PI => 3.141519; # close enough use GD::Text::Wrap; use GD::Text::Align; my $quote = [ grep { $_ } map { chomp; $_ } <DATA> ]; $quote = $$quote[rand @$quote]; my $author = substr $quote, rindex($quote,'--'), length($quote) -rindex($quote, '--'), ''; #my $gd = GD::Image->new(800,600); my $gd = GD::Image->new(800,600); $gd->colorAllocate(255, 255, 255); my $black = $gd->colorAllocate(0, 0, 0); my $red = $gd->colorAllocate(255, 0, 0); my $blue = $gd->colorAllocate(0, 0, 255); #$gd->transparent($red); $gd->interlaced('true'); $quote = GD::Text::Wrap->new( $gd, width => 800, # has no effect (a bug) line_space => 4, color => $black, text => $quote, preserve_nl => 1, ); $quote->set_font(gdLargeFont); $quote->set(align => 'center', width => 12 * 30); $quote->draw(10,10); $author = GD::Text::Align->new($gd, valign => 'base', halign => 'right', text => $author, ); $author->set_font(gdLargeFont); # STUPID API, always have to pass x,y, otherwise its undef my($left, $top, $right, $bottom) = $quote->get_bounds(10,10); $author->draw( $right , $bottom + 20, PI, $blue); $gd->rectangle( $left -10, $top -10, $right +10, $bottom + 35 , $red); # resize the image (even if it don't affect file-size much for png's) my $gd2 = GD::Image->new( $right + 12, $bottom + 37 ); #$image->copy(sourceImage,dstX,dstY,srcX,srcY,width,height) object $gd2->copy( $gd, 0,0,0,0, $right + 12, $bottom + 37 ); print qq{Expires: Thu, 01 Jan 1970 00:00:00 GMT Date: Fri, 02 Jan 1970 00:00:00 GMT Content-Type: Image/Png\r\n\r\n}; binmode(STDOUT); print $gd2->png(); __END__ A good way to threaten somebody is to light a stick of dynamite. Then + you call the guy and hold the burning fuse up to the phone. "Hear th +at?" you say. "That's dynamite, baby." -- Deep Thoughts by Jack Hande +y (SNL) Who ate my stick of butter?! -- butterman Once while walking through the mall a guy came up to me and said "Hey +, how's it going?". So I grabbed his arm and twisted it up behind his + head and said "Now whose asking the questions?" -- Deep Thoughts by +Jack Handey (SNL) The memories of my family outings are still a source of strength to me +. I remember we'd all pile into the car - I forget what kind it was - + and drive and drive. I'm not sure where we'd go, but I think there w +ere some trees there. The smell of something was strong in the air as + we played whatever sport we played. I remember a bigger, older guy w +e called "Dad." We'd eat some stuff, or not, and then I think we went + home. I guess some things never leave you. -- Deep Thoughts by Jack +Handey (SNL) Marta says the interesting thing about fly-fishing is that it's two l +ives connected by a thin strand. Come on, Marta. Grow up. -- Deep Tho +ughts by Jack Handey (SNL)

____________________________________________________
** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://202473]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2023-01-30 21:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?