Monks,

I'm done some text manipulation in perl, but I'm QUITE new to working with images and I've run into a bit of a problem. I'm just testing out some of the basic draw functions with the GD module that I'd like to use on a bigger more complex program. Start simple right? This is just supposed to draw an image and have the color go black to red on the x axis and black to green on the y axis.

The real problem I have is in the output of the picture (can be seen here: http://www.jasonmmoffett.com/alan_temporary/picture.png) Basically, about 1/3 of the way through scaling the x, the colors mess up. Is there a limit to the number of colors that can be defined with colorAllocate? Is there an easier way which you can define specific colors other than using a ton of colorAllocate calls? I dropped the actual number of colors used down because it was taking so long to run. Maybe a different drawing package all together would work better? Maybe I should try my hand in C? Really, I just need to be able to define colors based on equation output on a pixel by pixel basis. So I could have a script color any pixel in the image say 8-bits worth of color, or however many.

The code is below.

Thanks for your time!

-Alan

#!/usr/bin/perl #use strict; use GD; $width = 800; $height = 600; $outpizzle = new GD::Image($width,$height); #$outpizzle->interlaced('true'); #define a $%!@ ton of colors ... bad idea? for ($i=0; $i<10; $i++) { for ($j=0; $j<10; $j++) { for ($k=0; $k<10; $k++) { $colors[$i][$j][$k] = $outpizzle->colorAllocate($i*25,$j*2 +5,$k*25); } } } #draw some shizzle for ($i=0; $i<$width; $i++) { for ($j=0; $j<$height; $j++) { $outpizzle->setPixel($i,$j,$colors[int(10*($i/$width))][int(10 +*($j/$height))][0]); #print int(10*($i/$width))+"\n"; } } #output the picture open(PICTURE, ">picture.png") or die("uh oh spaghettio"); binmode PICTURE; print PICTURE $outpizzle->png; close PICTURE;

In reply to Image Editing with GD by alanonymous

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.