Well, the reason you can't find any documentation on doing other things with setpixel is that it would make no sense: a pixel is the atomic element of an image, like a character for a text file*. To attempt to manipulate a "bigger pixel" would be like asking tr to translate digraphs or words: that's not what it's for, and it doesn't really make sense to try to do it that way.

On the other hand, as the analogy suggests, there are mechanisms for dealing with larger blocks, in most well-designed schemes for manipulation: in the case of manipulating text in Perl, we have s///, and in the case of manipulating images in GD, we have filledRectangle($x1,$y1,$x2,$y2,$color) (among others).

The following code is an attempt to do what you seem to want to do: <disclaimer type="weasly">it is absolutely, completely and totally untested.</disclaimer>

my $rect_width = 10; my $rect_height = 10; for my $i (0 .. ($width - 1)/ $rect_width) { my $x_left = $i * $rect_width; my $x_right = $x_left + $rect_width - 1; $x_right = $width - 1 if $x_left >= $width; for my $j (0 .. ($height - 1) / $rect_height) { my $y_top = $j * $rect_height; my $y_bottom = $y_top + $rect_height - 1; $y_bottom = $height - 1 if $y_bottom >= $height; $im->filledRectangle($x_left,$y_top,$x_right,$y_bottom,$colors +[int(rand($total))]); } }

Preliminary testing indicates that this works--let me know if it doesn't. Have fun!

Update: as indicated, I got intimidated into testing (and finding the stupid bug, which is fortunate, isn't it?). Using the above as a drop-in replacement for the relevant lines of bladx's code, see the results at http://chemboy.perlmonk.org/bladx.cgi.

*Note that a pixel may have a varying amount of data behind it--between 1 and 32 bits, IIRC--just as a character may have 7 (ASCII) to 16 (Unicode) significant bits behind it.



If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders


In reply to Re: Changing setpixel size using GD.pm by ChemBoy
in thread Changing setpixel size using GD.pm by bladx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.