http://qs1969.pair.com?node_id=576758


in reply to Re^7: Perl Image Analysis
in thread Perl Image Analysis

GD can certainly read .png & .gif. I'm not sure about tiff.

For .gifs you need a fairly recent version (post the expiry of the .gif patent), but I use GD to create and manipulate .pngs all the time, and going back at least 4 years.

What are the errors you are getting when you try to load a .png?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^9: Perl Image Analysis
by lparsons42 (Novice) on Oct 06, 2006 at 22:04 UTC
    Actually, a closer inspection revealed that I had an earlier line in the script that I had forgotten that told it I was looking at Jpg files:
    my $MyImage = GD::Image->newFromJpeg($file, 0);
    I found that of course if I changed that line instead to
    my $MyImage = GD::Image->newFromPng($file, 0);
    That it will then happily read PNG files. Had I remembered having set GD to read Jpeg files, I probably would have realized that one earlier. Of course, the errors telling me that the file wasn't Jpeg probably should have clued me in, as well...

      If you use

      $image = GD::Image->new($filename)

      It will work out what type of image it is for itself--modulo those types it supports. A quick look at the docs didn't reveal any mention of .tiff though. .png is my preference anyway, as it compresses very well without any artifacts or side effects other than taking a few more milliseconds to load.

      By way of example:

      • A 66 MB 6600x3400 24-bit tiff containing 1565866 colours, which takes 1/3rd of a second to load.
      • Saved as a 24-bit .png with maximum compression reduces to 44 MB.

        Still contains 1565866 colours and shows no signs of of any artifacts even at 500% magnification. but it takes 3 seconds to load (and decompress).

      • Saved as a 24-bit .jpg at 'best' quality, it reduces to 20 MB.

        But now only contains 650125 colours, shows clear signs of the lossy algorithm even at modest magnifications and still takes 2 seconds to load (and decompress).


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^9: Perl Image Analysis
by gellyfish (Monsignor) on Oct 06, 2006 at 21:43 UTC

    For .gifs you need a fairly recent version (post the expiry of the .gif patent)

    Or of course a really old version before the GIF support was removed over the patent concerns :-)

    /j\

      I thought about mentioning that, but then realised that even if you could get your hands on the very old versions of the libgd sources, you'd probably need a very old version of Perl also to make the whole thing hang together.

      I did build GD from source once, but it was a pain to do, took ages to gather all the requisite bits together, and was genraly a PITA. Along the way I patched a couple of bugs, but then installed a later version of perl and screwed things up. After that I went back to using PPM to install it.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.