[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Image generation



On Sun, Jun 06, 1999 at 03:29:22PM -0400, Quentin Smith wrote:
> Yes, MacPerl includes the GD module, which can be used to draw gif images.
> In your case, the following script should work:
> 
> #!/usr/local/bin/perl
> 
> use GD;
> 
> $input = "0001010111110101100111111";
> 
> # create a new image
> $im = new GD::Image(5,5);
> 
> # allocate some colors
> $white = $im->colorAllocate(255,255,255);
> $black = $im->colorAllocate(0,0,0);
> 
> # make the background transparent and interlaced
> $im->transparent($white);
> $im->interlaced('true');
> 
> foreach $i (0..5) {
> foreach $j (0..5) {

I think you meant (0..4).  (0..5) would be for a 6x6 image.  Since you
multiply by 5 in the next line, you'll use some values twice (until you run
past the end of the string).

> if (substr($input, ($i*5+$j), 1) eq "1") {
> $im->rectangle($j,$i,$j,$i,$black);
> }
> }
> }

I think there must be a cleaner way to do this.

$width = 5;
for ($i=0; $i<length($input); ++$i) {
    $x = $i % $width;
    $y = int $i / $width;
    $im->rectangle($x, $y, $x, $y, $black)
        if (substr($input, $i, 1));
}


> # Convert the image to GIF and print it on standard output
> print "Content-type: image/gif\n\n";
> print $im->gif;
> 


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org