--- imgorig/wakautils.pl	2007-01-20 15:32:27.000000000 -0500
+++ img/wakautils.pl	2008-01-25 17:59:01.000000000 -0500
@@ -1088,7 +1088,7 @@
 	my (@res);
 
 	return ("jpg",@res) if(@res=analyze_jpeg($file));
-	return ("png",@res) if(@res=analyze_png($file));
+	return @res if(@res=analyze_png($file));
 	return ("gif",@res) if(@res=analyze_gif($file));
 
 	# find file extension for unknown files
@@ -1149,8 +1149,24 @@
 	my ($magic1,$magic2,$length,$ihdr,$width,$height)=unpack("NNNNNN",$buffer);
 
 	return () unless($magic1==0x89504e47 and $magic2==0x0d0a1a0a and $ihdr==0x49484452);
-
-	return ($width,$height);
+	
+	# So we know it's a valid PNG now, the only question is if it's an APNG too
+	
+	seek($file,8,0); # Jump to the end of the signature
+	while(1){
+		$bytes=read($file,$buffer,8);
+		last if $bytes!=8;
+		my ($length,$type)=unpack('NA4',$buffer);
+		last if $type eq 'IDAT'; # acTL must come before IDAT, so if we see an IDAT this is plain PNG
+		last if $type eq 'IEND'; # End of File
+		if ($type eq 'acTL'){ # It's APNG
+			seek($file,0,0); 
+			return ('apng',$width,$height);
+		}
+		last if seek($file,$length+4,1)==0; # +4 because of the CRC at the end
+	}
+	seek($file,0,0); 
+	return ('png',$width,$height);
 }
 
 sub analyze_gif($)
