Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-24 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found