in reply to GD VS ImageMagick Again...

For 2D polygon drawing and other vector graphics, I would recommend GD. If only because its interface is really straightforward, well documented (very much unlike Image::Magick) and fast.

As for transparency / alpha channels, GD allows for 7 bit alpha channels and 8 bit color channels. That should be enough if you're producing images for the web / in standard RGB. GD does not support CMYK as far as I know, which could be a serious problem if you're generating high-quality images for professional printing.

Image::Magick supports more file types and is generally easier to use for straight conversion and resizing etc. GD is fairly limited/low-level but it's well documented, fast, and easy to interface from XS (as in, it's easy to take a GD::Image object and throw some C/XS code at it).

All in all, Image::Magick kind of does what it sounds like: it applies "magic" to transform one image into another. GD on the other hand is a slightly more low-level toolkit.

If you need exactness you want GD. If you just want to convert stuff (and don't mind APIs changing on you every other version) you want I::M. If you want to do something that Image::Magick can't, and you don't mind spending an hour or two of focused coding, GD will probably let you do what you want with a minimum of fuss.

Also of interest (maybe): Imager. Which may be able to produce higher quality images than GD (and at least has a much larger API), but I haven't used it at all.

Replies are listed 'Best First'.
Re^2: GD VS ImageMagick Again...
by Burak (Chaplain) on Jul 28, 2007 at 21:30 UTC
    in short:

    1) GD: fast, but limited capabilities. Good documentation. Perlish interface.
    2) Image::Magick: slow but Photoshop-like capabilities. (VERY) Poor documentation. Weird interface.

    Imager looks nice and promising, but I haven't used it yet...

    And if you are talking about a web application and need availability, then GD is the winner in this category. Very widespead module...

      Thank you Burak and Joost, I tried to test these modules comparing (to my eyes only) the quality of the lines produced for the same png generation. IM seemed to perform a little better but not too much. When I draw on files 400x300px there are always some nasty little steps (sorry for my terrible english ;) ), especially with arcs or diagonal lines.
      I tried to draw a bigger image and to reduce it with IM and the result was far better. However in this manner there's much more elaboration for my poor pc.
      How is it possible that IM draws better when it manipulates than when it does the direct activity? Draw bigger and resize is the only solution to improve quality or there are smarter unfathomable ways?
      I'd like to create some chart creation module, no matter with GD or IM, It would be good if it was possible to achieve this line quality http://www.advsofteng.com/gallery_polar.html with images ranging usually from 400 to 600px
      In the past I read a thred discussing what is the quality in a chart. A chart shouldn't be too beautiful... That's not an answer.
      To sum up: How can I draw lines, arcs, etc without those little steps I mentioned before? I read somewhere that there are modules using the cairo library. Are there any other library? Which library are used by GD and IM? Do you know how to interact with them with perl and which should be the state of the art on linux?
      Is this a good way to proceed? Thanks in advance for every kind suggestion my dear monks

        There are several things you must do to get the best quality images out of GD. The defaults it uses are set up to be compatible with earlier versions of GD and so do not produce the best output unless you adjust them.

        1. Ensure that you create TrueColor images.

          Eg. my $img = GD::Image->new( 600, 400, 1 ); Without the 3rd parameter, it will produce paletized images.

        2. Use the AntiAliasing support ($img->setAntiAliased( $color )).

          Note that you need to set the color you are going to draw with to be the AntiAliased color before you draw with it. And switch it it, each time you draw with a different color.

          Also, when drawing in a foreground color that is not a good contrast with the background colors over which you are drawing, antialiasing can result in faded or fuzzy lines.

          Use $img->setAntiAliasedDontBlend( $color, 1 ) to disable antialiasing over particular color(s). It takes a little experiementation to work out what looks best.

        3. Use TrueType fonts.

          I've had trouble with this in the past, so I won't add anything more.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.