in reply to Loading PNG in Perl?

I've written code that generated PNG files by hand. Reading a PNG file isn't much harder. Both GD and ImageMagick do this quite nicely. There is a pureperl solution on CPAN, but I don't remember what it is. I found it a year ago when I was doing this, but it wasn't fast enough for my specialized use. (Turned out that my hand-tuned code was faster for my very specialized use than general purpose C code.)

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^2: Loading PNG in Perl?
by Xenofur (Monk) on Jul 31, 2008 at 03:12 UTC
    As mentioned above: GD seems to be for creating only. ImageMagick might do it, but i'm really leery of using such a huge package, since i need to include all the necessary dlls and such in the package of the project i'm working on.

    Speed is not a matter though.
      Oh? GD's docs are horrid, so I can see why you missed the following:
      my $image = GD::Image->newFromPng($filename); my ($height, $width) = $image->getBounds; foreach my $x ( 0 .. $width ) { foreach my $y ( 0 .. $height ) { my ($index) = $image->getPixel($x,$y); my ($r,$g,$b) = $image->rgb($index); print "($x,$y) -> ($r,$g,$b)\n"; } }
      That will print out the RGB value for every XY coordinate, row-first. There's a ton of other information you can extract. You just have to spend a few hours reading ALL the docs. It's well worth the effort.

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?