#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use Image::PNG::Libpng ':all';
binmode STDOUT, ":utf8";

for my $file (@ARGV) {
    if (! -f $file) {
        warn "Cannot find a file called '$file', skipping.\n";
        next;
    }
    my $png = create_read_struct ();
    open my $in, "<:raw", $file or die $!;
    $png->init_io ($in);
    $png->read_png ();
    my $ihdr = $png->get_IHDR ();
    for my $k (keys %$ihdr) {
	if ($k eq 'color_type') {
	    print "$k: ", color_type_name ($ihdr->{$k}), "\n";
	}
	else {
	    print "$k: $ihdr->{$k}\n";
	}
    }
    my $text = $png->get_text ();
    if ($text) {
	my $i = 0;
        for my $t (@$text) {
	    $i++;
            print "Text chunk $i:\n";
            for my $k (keys %$t) {
                my $v = $t->{$k};
                if (! defined $v) {
                    $v = 'undefined';
                }
		if ($k eq 'compression') {
		    $v = text_compression_name ($v);
		}
                print "$k: $v\n";
            }
            print "\n";
        }
    }
    my $time = $png->get_tIME ();
    if ($time) {
	print "Modification time:\n";
	for my $k (qw/year month day hour minute second/) {
	    print "$k: $time->{$k}\n";
	}
    }
}

# Local variables:
# mode: perl
# End:
