#!/usr/bin/perl
# -*- perl -*-

while (<>) {
    $line = $_;

    while ($line =~ s@img src=\"([^\"]+)\" alt@sprintf("img src=\"%s\" %s alt", $1, &pngsize($1));@e) {
    }

    print $line;
}

sub pngsize {
    my ($file) = @_;
    my ($x, $y);

    open(PI, "pnginfo $file |");
    while (<PI>) {
	if (/Width: (\d+) Image Length: (\d+)/) {
	    close PI;
	    return "width=$1 height=$2";
	}
    }
    close PI;
    return "";
}
