Hey everyone - wow, it's been a long time since I posted here (school, work, etc. taking all my time) - I missed this place!

Anyway, in my quest to finally get back to Perl after a year of using Java and C in a forced academic enviornment, I decided to start playing around with the GD.pm module from Lincoln Stien.

I have an image gallery on my website, and I wanted to (because I use Image::Magick to do dynamic resizing anyway) add dynamic text to the images such as a caption that will be held in a database somewhere else. Therefore, GD immediatley came to mind.

So, say I have a file my_image.png, and I want to use GD to simply add the string "TEST!" to the top left-hand corner of the image and re-print it:
use GD; # read the image my $gdimg = GD::Image->newFromPng("my_image.png"); # we need a color for our text my $green = $gdimg->colorAllocate(0,255,0); # write the string "TEST!" to the image $gdimg->string(gdMediumBoldFont, 5, 5, "TEST!", $green); # get the new image my $data = $gdimg->png; # write it out binmode STDOUT; print $data;
Running the above script, color pallete becomes GREATLY reduced, even though the image format stayed the same (PNG all the way through). The same happened if the calls to $gdimg->colorAllocate() and $gdimg->string() are completely removed, so that basically all that is happening is a read/write of the file through the GD interface. Printing out $gdimg->colorsTotal() returns only 256. As an example, check out these two images:

Original: New Window
GD'ed: New Window

As you can see from even these small thumbnail files, the color pallete has been reduced unacceptably (and it's even worse for larger files). Does anyone have any ideas why this might be happening? Thanks a bunch everyone - it's great to be back!

r. j o s e p h
"Violence is a last resort of the incompetent" - Salvor Hardin, Foundation by Issac Asimov

In reply to GD reducing pallete causes major problems. by r.joseph

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.