As handy as GD is, it is strictly an 8-bit tool, and as such even if you do no manipulations at all to your 24-bit PNG, it will still end up with just 256 colours. This is mentioned in the docs, but in my version it is only with reference to jpeg files, however the original docs on Thomas Boutell's site confirm that it is 8-bit for PNG also (apparently true colour support is planned for version 2.0 however).

My advice is to use GD for schematic graphing and charting (limited pallettes), or for generating tiny thumbnails, but use something else if you need quality.

Updated: clarified that the starting PNG image was indeed 24-bit, re: hossman's response

Update 2: The PNG standard states that pallettes be 256 8-bit colours only, but apparently that is not always the case either.

Update 3: I don't see how the above is misleading, though I suppose it may be considered incomplete (but that's why I linked to the full document ;-). Certainly PNGs are not required to have pallettes, but if they do they can only hold up to 256 colours, and those colours are only 8-bits for each of red, green and blue. That's all I meant to say - honest! ;-)

More fodder to show your final line of speculation is correct: If you continue to read the GD docs, check out "What's new in version 1.6.1" and you will see that all non-pallette PNGs are pallettized "badly, by dithering them", and that surely must be the true root of this problem. Just below that you will see that version 1.6 of GD was the first to support PNGs, and then it was only PNGs with pallettes, so 1.6.1 was just a quick hack to accept a wider variety of PNGs.

--
I'd like to be able to assign to an luser


In reply to Re: GD reducing pallete causes major problems. by Albannach
in thread 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.