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

44 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.
    1. Re:Nice GD Info by Greedo · · Score: 2, Informative

      PHP has always support GIF reading. They took the GIF writing support out when Unisys were being dinks.

      --
      Tuus crepidae innexilis sunt.
  2. Did anyone really stop using gifs? by Neil+Blender · · Score: 3, Insightful

    I know I didn't.

    1. Re:Did anyone really stop using gifs? by ron_ivi · · Score: 2, Insightful
      Only those people with no respect for intellectual property rights kept using them.

      I find it interestingly ironic that most commercial software disrespected IP-rights by continuing to include GIFs, while the open source community showed far more respect for intellectual property law by going through great effort to avoid violating such patents.

    2. Re:Did anyone really stop using gifs? by Tumbleweed · · Score: 4, Insightful

      For 'many' of the uses? Hardly. If you save a PNG as 24-bit, even though it has 8-bit or fewer colours, even pngcrush (or the better such program, pngout) can't help much. Saving a PNG properly, THEN using pngout will almost always produce a smaller filesize than GIF. It's _exceedingly_ rare that you'd have a smaller GIF - usually only when you're using a 1 pixel transparent GIF for a web site spacer graphic, which you _should_ know how to avoid doing by now, anyway, if you're anything resembling a well-informed web developer.

      Bah. A pox on GIFs!

      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 & pngout.

    3. 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.

    4. Re:Did anyone really stop using gifs? by jonknee · · Score: 3, Informative

      So I guess you don't see images on Slashdot? Pretty much all graphics on this site are .gif.

    5. Re:Did anyone really stop using gifs? by kirun · · Score: 2, Informative

      That's quite a neat trick, and almost completeley useless. Well done :)

      --
      I'm scared of numbers that can't be written as a fraction. It's an irrational fear.
    6. Re:Did anyone really stop using gifs? by Pieroxy · · Score: 2, Insightful

      The problem is not user error. I use Photoshop and ImageReady for my icons/pictures processing purposes. I have very rarely encoutered an icon that would be smaller with PNG. So I still stick to GIF for most purposes.

      Now maybe the PNG compresor is a piece of crap in IR. How am I supposed to know? I'm not going to try 100 different compressors.

      A format that has no decent popular implementation will fail. No matter how good it is. This is a MAJOR problem for PNG. And it is not a user error.

    7. Re:Did anyone really stop using gifs? by Tumbleweed · · Score: 4, Interesting

      > only posers that code only for the bleeding edge pan the old tricks
      > do you get the point I am making?

      Yep, I do. People like YOU are posers. CSS is hardly 'bleeding edge.' People like YOU are what's holding back 4-year-old standards from becoming requirements. The point you're making is that you're a shortsighted idiot with little real comprehension of the impact of the things you do.

    8. Re:Did anyone really stop using gifs? by Tumbleweed · · Score: 3, Informative

      > Why would you want to save an image with less than 256 colors as PNG-24 when
      > this is precisely what PNG-8 is for?

      Dude, that's what I'm _saying_. Many people don't realize that, and thus save their images with a higher palette than is necessary, and then complain that PNG doesn't compress as well as GIF. Photoshop doesn't tell you that when you save your file - you have to check the colour depth and change yourself. These same people also don't seem to use the post-creation compression tools to get the real compression benefit that can be had with PNG.

      > At least 30% of the website icons I create are smaller as GIFs.

      Are you compressing your PNGs with pngout or pngcrush? (pngout usually works much better) What kind of colour depth are we talking here?

    9. Re:Did anyone really stop using gifs? by ljaguar · · Score: 2, Informative

      Opera displays it fine too.

  3. Unisys by Anonymous Coward · · Score: 2, Insightful

    I bet nobody in Unisys (at least nobody high up) even knew about this happening ... otherwise they would have realized they weren't making money in the last year and put it in the public domain and made a press release etc.

    Shows you that a corporation like Unisys isn't dynamic. RSA on the other hand, was making money off their patent and decided that there's value in releasing it into the public domain prior to the patent expiration date.

  4. obligatory warning by Anonymous Coward · · Score: 4, Funny

    Beware of Geeks bare in GIF's.

  5. Gif is only good for animation by wheany · · Score: 4, Insightful

    The only thing gif does better than png is animation. Okay, on some rare occasions, gif compresses better. But most of the time, you have no reason to use gif instead of png.

    1. Re:Gif is only good for animation by rjamestaylor · · Score: 3, Insightful

      Beta was and is better than VHS. Anyone understanding video would choose Beta over VHS. Millions of average people began buying VHS machines because they were cheap. Millions more began buying VHS machines because they would play other people's tapes. Beta, the superior technology, lost to the cheaper, "good enough" VHS because of market adoption. Internet Explorer has and will always have GIF support. Its PNG support is less than optimal. Got something you want everyong to see? Use GIF.

      --
      -- @rjamestaylor on Ello
    2. Re:Gif is only good for animation by Ark42 · · Score: 2, Informative


      IE supports 256color PNG files with a single palette transparency with no JS or special crap like is required to support the 32bit PNG's alpha channel.
      The PNG is usually smaller too.
      Unless you need animation, PNG is just better.

    3. Re:Gif is only good for animation by jwymanm · · Score: 2, Informative

      You can display PNGs with full alpha transparency, both as backgrounds of a block element and inline with an image tag, without using any javascript, behaviors, or a second image.

      The following CSS and html code shows how:

      For background:

      <style>
      #mydiv {
      width:Xpx; height:Xpx;
      background:url('mydiv.png');
      filter: progid:DXImageTransform.Microsoft.AlphaImageLoader (src='image.png');
      background:expression('none');
      }
      </style>
      <div id="mydiv"></div>

      For inline:

      <style>
      #mydiv {
      width:Xpx; height:Xpx;
      filter:progid:DXImageTransform.Micros oft.AlphaImageLoader(src='image.png');
      }
      #myimg {
      width:Xpx;height:Xpx;
      filter:progid:DXImageTra nsform.Microsoft.Alpha(opacity=0);
      }
      </style>
      < div id="mydiv"><img id="myimg" src="image.png"></div>

      Of course you'll want to put the proprietary code within IE comment conditionals [link here]. You can remove the expression syntax from background if you put it within the IE conditional. Fix any obvious errors in the above code that /. introduced.

  6. Ancient technology by AKAImBatman · · Score: 2

    GIFs are great for animations, but I really do prefer PNGs at this point. While it really isn't that big of a deal, PNGs are simply smaller and look better. If we could just get Microsoft to fix Internet Explorer, we'd have a new defacto standard for all non-photographic images.

    1. 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.
  7. What format war? by xxxJonBoyxxx · · Score: 2, Insightful

    Can you show me a mainstream, modern browser that doesn't understand both GIF and PNG?

    1. 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.

  8. Answer to the inevitable PNG Slashbots by IGnatius+T+Foobar · · Score: 5, Insightful

    The usual crowd of nincompoop Slashbots are going to crow "They should just leave it out! Everyone should use PNG anyway!!"

    Let me answer that in advance by reminding everyone that GIF is a useful format. Everything can read it and display it. It's been around for two decades and is now a completely open and unencumbered standard.

    And let's not forget that when you need to display an image that is non-lossy, and supports transparency, and displays properly in Internet Explorer (shame on you for using Internet Explorer in the first place, but we'll accept that a lot of people still do) ... GIF is still the only available option.

    --
    Tired of FB/Google censorship? Visit UNCENSORED!
    1. Re:Answer to the inevitable PNG Slashbots by Anonymous Coward · · Score: 2, Insightful

      when you need to display an image that is non-lossy, and supports transparency, and displays properly in Internet Explorer

      We'll ignore the fact that GIF is limited to 256 color non-lossyness, but which of those does 8-bit PNG not meet? It's just as non-lossy as GIF, it supports single bit transparency (just like GIF), and it displays properly in IE. Now, IE has trouble with 24bit color PNG with transparency, but that's not something GIF is capable of.

    2. Re:Answer to the inevitable PNG Slashbots by LionMage · · Score: 2, Informative
      PNG may have a size advantage, but seems to render much slower. If you include transmission and rendering time in the total picture, gif beats png by a large margin.

      This is purely subjective, and FUD. On a modern CPU, with a modern graphics card, both GIF and PNG should take the same amount of time to "render." The process of rendering includes taking the data, decompressing it, and writing the pixels to the display device.

      It's quite possible that some web browsers may have a very broken PNG rendering engine, but that's not a fault of the file format. PNG was designed to render progressively as it's downloaded, just like GIF. (I should know, I'm one of the specification co-authors for PNG.) PNG also has a much cooler interlacing scheme than GIF, which has made it a favorite for many set-top box developers (think next generation cable boxes).
  9. 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"?
  10. Re:PNG is still better by sdkaneda · · Score: 2, Informative

    IE6 botches gamma correction on PNG8 images. Try making a PNG8 file and a GIF filled with #B0B0B0 and place them on a web page with a background colour of #B0B0B0. In IE, The PNG displays as a slightly different shade of grey.

    --
    #roses { color: #ff0000; } #violets { color: #0000ff; }
  11. Ancient software? by Inominate · · Score: 3, Informative

    Any browser which doesn't support PNG is also not going to deal well with the rest of basicly all websites, or anything else on the modern internet.

    IE displays PNG's properly, with transparency, and it's still non-lossy. IE only doesnt properly support the alpha channel of PNG's.

  12. Re:Seeking legal advice by Kphrak · · Score: 3, Insightful

    It's YRO not because GIFs could violate your rights online, but because Unisys, the holder of a submarine patent on GIFs, could. That's one of the main reasons we switched to PNG. Now the patent expired, meaning our rights to use GIFs, without getting the pants sued off us, are back.

    Please increase your clue level before posting. The article is correctly filed.

    --

    There's no sig like this sig anywhere near this sig, so this must be the sig.
  13. Re:PHP by Greedo · · Score: 2, Informative

    PHP isn't the only thing to use GD, although I'm guessing it's the most popular one.

    --
    Tuus crepidae innexilis sunt.
  14. Re:Digital Cams ? by rusty0101 · · Score: 2, Insightful

    I would suspect that camera developers chose JPG because it was a specification from the Joint Photographers Group (hence it's name). If you are going to sell something to photographers, you want to tie it to a standard that photographers are expected to approve of.

    Note, I am not saying that it was the best standard to choose, simply that it made sense from a camera developer's standpoint.

    I doubt seriously that GIF will be a standard for camra developers to select and store to.

    I susect that for the forseable future, uncompressed images will be saved to TIFFs, and compressed (lossy) will be stored as JPG files. How long this status will stay, I can't predict, neither can I predict what standards will take over.

    -Rusty

    --
    You never know...
  15. GIF is evil by fiannaFailMan · · Score: 3, Funny
    Gif is only ever used for annoying animated banner ads! It's not capable of doing anything else! Gif is evil! Gif is used by bozos! I hate Gif! Yadda yadda yadda.....

    [There. That should earn me some karma if the recent Flash flame war is anything to go by.]

    --
    Drill baby drill - on Mars
  16. Re:Digital Cams ? by maxume · · Score: 3, Informative

    Yep, you are wrong.

    png uses lossless compresion. It basically is a format for zipped bitmaps.(as far as the compression works, it does a whole bunch of other stuff that bitmaps don't.)

    jpeg uses some lossy compression, and then goes ahead ahead and uses lossless on the output of the lossy compression stage. This yields smaller file sizes at a given image resolution(and thus better resolution at similar file size), by sacrificing some amount of quality. The reduction in quality is tunable, and using high quality settings results in images that are fine for most purposes, with the major exception being high quality print.

    gif doesn't support color nearly as well as jpeg or png.

    Basically, jpeg is 'good enough'(for most people, those that it isn't good enough for use stuff like raw formats or tiff+lzw), and already widely supported/in use.

    for more info, check out http://www.photo.net/learn/jpeg/
    it is a decent summary of jpeg and the issues involved with its use.

    --
    Nerd rage is the funniest rage.
  17. screw gd, use imlib by xshader · · Score: 2, Informative

    gd is SLOW when rescaling images. out of all the libs i tested, imlib2 was the fastest by far. imlib2 scales all my images on my personal photo album on-the-fly and the processor usage is never an issue.

  18. Wrong by adiposity · · Score: 4, Insightful

    Unless you know the business internals and license agreements of those companies, you have no idea whether they respected the patents or not. However, all major graphics program vendors (Adobe, JASC, etc.) have LICENSED the gif compression algorithm, and used it in their programs. Those who paid to use those programs have the right to create gifs.

    These commercial softwares did not disrespect "IP-rights," they meticulously followed the law by doing exactly what's required to use the patented algorithm. They showed respect for the patent by paying to use the algorithm. Free software respected the same rights by not using what they hadn't paid to use (because they either couldn't or weren't willing to).

    -Dan

    1. Re:Wrong by scottj · · Score: 2, Insightful

      EXACTLY! My photoshop-created GIFs were not disrespecting any patents or laws. They were fully and completely licensed. That fact that the license for the GIF code wasn't free didn't make it any less legal. It was merely commercial software.

      But now that it's returning to the public domain finally, I have found that I prefer PNG and its alpha transparency to GIFs. It seems that Unisys' actions provided an incentive to innovate rather than stifling creation.

      --
      .-.--
  19. Re:Digital Cams ? by pclminion · · Score: 2, Informative
    Could anyone on the know tell the rest of us why is it that digital cameras choose JPG as the compressed format instead of PNG?

    PNG doesn't handle photographs well. The compression in PNG comes from the zlib compression library. It is based on detecting repetitive patterns. In a photograph there do not tend to be repetetive patterns, because of the nature of the scene being photographed, and because of noise in the camera's light detecting instrument, which tends to break up any patterns.

    PNG has a set of predictive filters which can be applied to an image to attempt to increase the compression effectiveness. However, these are simplistic and are designed to be optimal for non-photographic images.

    Looks to me like PNG would typically provide better image resolution for a similar filesize. Maybe I am wrong.

    Yeah, wrong, but that's okay :-)

    And also, is GIF an option now that it is free again?

    No. GIF is an indexed-mode format, and only supports 8-bit palettes. In other words, a GIF can only have 256 colors. Nobody would ever want to store photographs in such a format.

  20. Re:PNG and non-metric resolution? by pclminion · · Score: 3, Informative
    I know this is off-topic, but why is it that if I save a PNG file with a resolution of something like 300 pixels/inch, and then re-open it, it comes back in as 299.999 dpi?

    See this portion of the PNG spec. The image resolution is stored in the PNG file as an integer number of pixels per meter.

    There are 39.3700787 inches in a meter. Thus, a 300 pixels-per-inch image is 11811.02361 pixels-per-meter. However, the PNG can only store an integer number of pixels per meter. Thus, 11811.02361 gets rounded to 11811.

    Convert back to inches. What is 11811 / 39.3700787? Why, it's 299.9994 pixels-per-inch!

    That's why 100 pixels per centimeter works perfectly. It's in metric.

    Stop using this silly "inch" things, and your problem will vanish.

  21. 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.

  22. They didn't have to by Wokan · · Score: 2, Informative

    PHP supported the use of older GD libraries on Windows, some of which still have the GIF support in them. All PHP had to do was not remove the capability detection they already had.

  23. 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.)
    1. Re:I may owe you an apology... by femto · · Score: 3, Insightful
      You have just illustrated a shortcoming of proprietory software. MS (or predecessor) wrote a library, licensed it to Adobe and that is where it stayed.

      *If* MS and Adobe were free software projects, Adobe would have gotten its simplified PNG library and had a product to market just as quickly. Another person could then have come along and at a later date and implemented the remaining filters. In this way Adobe gets a working product quickly, but at a later any missing features get filled in.

      As it is the proprietory model delivered the fast product, but missed out on the 'incremental improvement' stage.

  24. Re:PHP by scottj · · Score: 2, Insightful

    PHP is definitely not the only user of GD. Heck, GD is a C library. There are a lot of C apps out there that use it.

    Personally, I've only used GD via perl and the many perl libraries that use it, primarily GD.pm.

    --
    .-.--
  25. *bzzzt* WRONG! by Jeedo · · Score: 2, Informative

    It's the Joint Photographic Experts Group. There is a fairly large difference between a photographer and a photograph(ic).