Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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

by myocom (Deacon)
on Aug 21, 2001 at 03:31 UTC ( [id://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

Replies are listed 'Best First'.
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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-07-23 02:11 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.