Slashdot Mirror


GIF Support Returns to GD

g_adams27 writes "Legions of geeks and developers owe a debt of gratitude to Tom Boutell and his "gd" library, which powers the drawing and graphic-generating tools used by dozens of open-source projects. And now, with the expiration of the last Unisys patent on the GIF format, support for GIFs has finally been reinserted in gd. The GIF/PNG/MNG wars may continue, but having more options is good!"

7 of 364 comments (clear)

  1. Nice GD Info by mfh · · Score: 4, Informative
    I'm not sure if the PHP guys saw this coming or not, but gd_info() (PHP 4 >= 4.3.0, PHP 5) will detect GIF support, so you can tell if you've got the thing set up correctly with a nice little one-liner:

    var_dump(gd_info());

    Some nice soul posted a comment on PHP.net that has what appears to be a great function that does the same thing, but could be used in install scripts and hacked to get it working the way you want:
    /**
    * Get which version of GD is installed, if any.
    *
    * Returns the version (1 or 2) of the GD extension.
    */
    function gdVersion() {
    if (! extension_loaded('gd')) { return; }
    ob_start();
    phpinfo(8);
    $info=ob_get_contents();
    ob_end_clean();
    $info=stristr($info, 'gd version');
    preg_match('/\d/', $info, $gd);
    return $gd[0];
    } // end function gdVersion()

    // The function is easy to use.

    if ($gdv = gdVersion()) {
    if ($gdv >=2) {
    echo 'imageCreateTruecolor() and imageCopyResampled() functions may be used.';
    } else {
    echo 'imageCreate() and imageCopyResized() functions must be used.';
    }
    } else {
    echo "The GD extension isn't loaded.";
    }
    --
    The dangers of knowledge trigger emotional distress in human beings.
  2. Re:What format war? by wkitchen · · Score: 5, Informative

    Not complete lack of support, but IE's PNG support is partly broken. Mostly in that it doesn't support alpha transparency, though all other major browsers do. And that's a real shame because it's a very nice feature. This alone would give PNG a clear advantage over GIF if it wasn't for the fact that the only major browser that doesn't support it happens to account for over 90% of the user base.

  3. Re:IBM by Tassach · · Score: 4, Informative
    "That Sonny Bono thingy", properly known as the Sonny Bono Copyright Extension Act, extends the duration of copyrights, not patents. If you're unsure of the difference, do some research.

    Since it's a duplicate patent and should never have been issued in the first place, IBM would be idiotic to let it get anywhere near a courtroom.

    --
    Why is it that the proponents of "one nation under God" are so eager to get rid of "liberty and justice for all"?
  4. Re:Ancient technology by ncc74656 · · Score: 4, Informative
    Full Alpha, or just transparency?

    Full alpha...here's one script that implements it, and you use it something like this (assuming that you've loaded the script somewhere further up in your page):

    <span id="foo">
    <img src="foo.png" alt="Foo" title="Foo" width=320 height=240>
    </span>
    <script type="text/javascript">
    DisplayPNG("foo", "foo.png", 320, 240, "Foo");
    </script>
    --
    20 January 2017: the End of an Error.
  5. Re:Did anyone really stop using gifs? by Ark42 · · Score: 4, Informative


    GIF may be indexed color, but since the animation extension is supposed to allow for multiple palettes that DO NOT overwrite the previous palette, as well as the ability to have each frame render a small piece of a larger picture with mostly transparent background, you can "draw" a true color GIF.

    See gif-with-32697-colors.gif
    If your browser draws it right, it will look like this

    Note that the GIF is 180K and the PNG is 14K, but they are both truecolor.
    Unfortunately, many non-animated programs will only display the first frame, so you only see the upper left corner, and some will improperly overwrite the palette of every frame with the current frame's palette, causing the image to pulse widely as it draws and end up in the wrong colors.

  6. Re:PNG Software support by cwilson · · Score: 4, Informative

    (a) It was actually only a couple of months after Unisys announced its patent and its intent to enforce, before the PNG format was finalized. It was really an example of lightning-speed format development. google "png history"

    (b) the worldwide patents on LZW have not yet expired! It's arguable whether the following patent is valid, but IBM was issued a patent on *the same algorithm* covered by the Unisys patent -- and IBM's patent is good for another two years:
    United States Patent No. 4814746 issued in 1989.

  7. I may owe you an apology... by LionMage · · Score: 4, Informative
    Now if only Adobe could get off their lazy crappy-programmer asses and put proper PNG compression in Photoshop so we wouldn't need programs like pngcrush [and] pngout.

    I used to work for a company named Mastersoft, which was acquired by Frame, the makers of Frame Maker (the now-discontinued DTP app); Frame was subsequently acquired by Adobe.

    While at Mastersoft, I developed an implementation of a PNG reading and writing library for use in various file format conversion products; these reading and writing libraries were also licensed to OEMs for inclusion in other commercial products, so they're in a lot of places. The libraries I wrote used Jean-Loup Gailly's (sp?) zlib (since I didn't want to reinvent the wheel and debug a compression library), but did not rely on the pnglib reference implementation in any way.

    I was very proud of the fact that my libraries were the first commercial implementation of PNG, as far as I can tell. However, due to time constraints and some performance requirements, the compression done by my PNG writer libraries wasn't the best. Specifically, I avoided using any scanline filter type other than Paeth for my PNG writing library; most modern PNG writers will try all 5 filter types on each scanline, and see which compresses the best. My choice had the virtue of saving time in writing a PNG file to disk, but doesn't necessarily produce the smallest PNG files. I also used a relatively small PNG chunk size; since each chunk has some overhead, more chunks means larger PNG files. Lastly, the version of zlib that I used was current as of the drafting of the original PNG specification; subsequent versions of zlib were released which were slightly more efficient, and a few nasty bugs were stomped out.

    I don't know if Adobe is using my PNG writing code in Photoshop, but since Adobe purchased the IP of Mastersoft in the Frame acquisition, it's not inconceivable that they used my code rather than writing their own. If they used my code, then it's quite possible that I'm to blame for Photoshop saving out crappy PNG files that are too big.

    In my defense, though, I should say that many people did manage to compress existing GIF files using my PNG library (which shipped as part of the Mastersoft File Utilities by Adobe, a product that unfortunately didn't last long); one magazine reviewer specifically used this software suite to convert a bunch of GIFs to PNGs, and concluded that in most cases, the PNGs were indeed smaller.

    As soon as you start dealing with non-indexed color images, though, PNG is no better than TIFF. Some folks might incorrectly try to take a 24-bit source image and save as PNG, then take the same source and save as GIF, and will note that the GIF is way smaller -- as it should be, since GIF doesn't support 24 bpp images, whereas PNG does. To save a 24-bit source image as GIF, you have to first reduce the color space and convert to an indexed color image, since that's the only type of image that GIF can store. With PNG, the bit depth of the original is preserved. (And since PNG supports up to 16 bits per channel, and supports up to four channels -- R, G, B, and Alpha -- you can see how a PNG image can get obscenely large. This is where it pays to manage your expectations and understand the features and limitations of the file format.)