I've written code that generated PNG files by hand. Reading a PNG file isn't much harder. Both
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.)