Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Random Pictures Using .pngs ... how?

by myocom (Deacon)
on Aug 21, 2001 at 03:31 UTC ( #106424=note: print w/ replies, xml ) Need Help??


in reply to Random Pictures Using .pngs ... how?

GD can do this (and more). Here's a quick 'n' dirty example that will create a 100x100 pixel PNG and spew it to STDOUT (so make sure you redirect to a file in your shell).

use strict; use GD; my $im = new GD::Image(100,100); my @colors; # Preallocate colors, since PNG has a limited number of co +lors for (0..255) { $colors[$_] = $im->colorAllocate(int(rand(256)),int(rand(256)),int(r +and(256))); } for my $x (0..99) { for my $y (0..99) { $im->setPixel($x,$y,$colors[int(rand(255))]); } } binmode STDOUT; print $im->png;
"One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison


Comment on Re: Random Pictures Using .pngs ... how?
Download Code
Re (tilly) 2: Random Pictures Using .pngs ... how?
by tilly (Archbishop) on Aug 21, 2001 at 04:37 UTC
    Before your print add:
    print "Content-Type: image/png\n\n";
    and your script is now a CGI script that can be put behind a webserver. There is now no need for a temporary file!
Re: Re: Random Pictures Using .pngs ... how?
by bladx (Chaplain) on Aug 21, 2001 at 08:48 UTC
    Thanks, myocom for the quick intro to the awesome GD module! It is a very useful module for me, and the documentation is very lengthy, however very useful.

    Thanks tilly for showing me how to make this useful for CGI, since I tend to program in CGI more often than the shell usually.

    I will be continuing to experiment with the GD module, and see if I can't get really good at utilizing this module for some really cool Perl artwork *hopefully*!

    Andy Summers

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-09-18 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls