bladx has asked for the wisdom of the Perl Monks concerning the following question:

Recently I have heard many good things about the graphics format .png. It has been around for a while, but I haven't really noticed it until this year, and I was wondering something about it as compared to .gif or .jpg graphics files.

I heard that Perl works better with .png's than with any other type of standard internet type graphics formats. Is this true? Or do people simply choose .png's over .gifs to edit in Perl?

I was curious about this, because I am a graphics designer as well as a beginning programmer, and am interested in how I can best change the appearance of graphics without having to create a new one for every different color, etc. So I am sincerely interested in finding out if .png's are better than .gif's for this type of Perl work.

Thank you very much!

Andy Summers
  • Comment on Which graphics format can Perl alter easier and more?

Replies are listed 'Best First'.
Re: Which graphics format can Perl alter easier and more?
by Jouke (Curate) on Aug 12, 2001 at 16:40 UTC
    There is no graphical format that Perl is "better" or "worse" in. We (probably) all know the problems there are with the .gif format because of Unisys' patents on the LZH algorithm. Therefore packages like GD officially no longer support .gif.

    The .png format came as solution to that and it is fully supported by modules like GD, so that's no problem. The .jpg fileformat has just other applications, it's more suitable for photos.

    There is no 'better' involved in the choice between gif and png, it just has to do with the licensing issues of the LZH algorithm in gif, which isn't an issue in .png

    Jouke Visser, Perl 'Adept'
    Using Perl to help the disabled: pVoice and pStory
      Do be aware that GD is only able to handle 8-bits of color, and will 'posterize' (reduce the colors) of any higher-color image. For some cases, this may be acceptable, but is typically not the norm.

      If you need better color support, you'll probably have to go with a module like Image::Magick that uses the ImageMagick library to support nearly all popular formats and 24-bit+ color.

      I do wonder, now that I think about it, on the usefulness of a perl mod to handle 'object-oriented' raster imaging, similar to how the Macintosh PICT format is handled; objects would be stored nicely in XML until the need to be render is needed, and then backend off something like Image::Magick to actually do the generation.

      -----------------------------------------------------
      Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

        I used GD just as an example. It's one of the available graphics manipulation modules for Perl, just to explain that there is no graphical fileformat that Perl handles better or worse.

        Jouke Visser, Perl 'Adept'
        Using Perl to help the disabled: pVoice and pStory
        Ok, so would Image::Magick also support altering the appearance of .jpgs as well? I am interested in being able to alter the look of .jpgs besides .pngs also.

        Is there a way to do this?

        Andy Summers
      I'm not a graphics enthusiast but I seem to remember reading that the png format supported things that gif doesn't offer, like 32 bit true color and semi-transparency. I think there's a bit more to it than licensing issues. I did a quick read through the faq on the png site which looks like a good stop for anyone wanting some real details.

      Hey... it even looks like Oreilly has a book out on the png format if you're into that sort of thing.

      Ira,

      "So... What do all these little arrows mean?"
      ~unknown

Re: Which graphics format can Perl alter easier and more?
by lemming (Priest) on Aug 12, 2001 at 22:38 UTC

    The advantage of png over jpg is that png is not a lossy format. If you resize a jpg, you'll lose some detail.

    And Image::Magick supports both formats.

      Wow, I did not realize that if you resize .png's that they don't lose their detail. That is one of my erks about using .jpg's, because once you try to resize it even in a little bit, you can tell it has been resized.

      This must explain why many friends of mine on the internet have begun to use .png's frequently ( I didn't realize that there were some very useful reasons to use .png's :) )

      Thank you for the help, and for recommending Image::Magick! This information will prove to be useful as I am a graphics enthusiast as well as a programmer.

      Andy Summers
        Resizing in any format will lose detail!

        However, a highly-compressed JPEG that looks OK in normal use will go very wrong very quick if you start manipulating it. The compression artifacts, just below your visibility threshhold originally, really mess things up.

        Zoom in on a JPEG and you'll see the artifacts I'm talking about. It's called "scambled eggs" or "mosqueto legs".

        —John

        Hmm, ok when I said resize I should of said any manipulation of jpeg will degrade it due to it's lossy compression. You can edit png files and save them without having the file lose detail. A decent intro into the png format is this: png intro

Re: Which graphics format can Perl alter easier and more?
by John M. Dlugosz (Monsignor) on Aug 13, 2001 at 06:58 UTC
    What do you mean by "easier"? If programming in individual pixel access, it's simplest to treat the image as a 2D array of pixels.

    If using a library like ImageMagick, they are all equally easy because you use the same API.

    "better with PNG" isn't just Perl, it's because libpng is promoted to go along with the png format, so any program can easily incorperate png support.

    Choose PNG over GIF: well, there is a little problem with licencing fees. So you will find no (legal) free GIF software anymore, since nobody will pay $5000 to be allowed to code something which he'll then give away. PNG is better in every respect (by design) except as an animation format, so just use PNG and forget GIF.

    If you just want to change a color globally, look into color-indexed modes rather than true color modes. Then you just change the value once, as the image data actually refer to the palette index.

    Note that PNG allows for transparancy and alpha-blending, so maybe what you are really looking for are transparant sections?

    —John

Re: Which graphics format can Perl alter easier and more?
by nehlwyn (Acolyte) on Aug 13, 2001 at 03:55 UTC
    Greetings fellow monk,

    you may have had enough answers already but i might add this short one as another way to understand your question .

    Certainly ( i'm not sure , not being graphics-aware enough ) , Perl can handle any image format but there are perhaps some that are better than the others considering Perl innate abilities .

    The formats that don't use encoding like pixmap may be among those if you think about the easiness with which Perl manipulates raw data .

    It greatly depends on your purposes but this point of view may be to consider ...

    What do you think ? ( you don't really need to answer , that was just my way to conclude this contribution ... ;-).

    the little one.