sub imgtype 
  {
	my $file  = shift;
	my %types = (
		'BMP'	=> qr/^BM/,
		'GIF'	=> qr/^GIF8[79]a/,
		'JPG'	=> qr/^\xFF\xD8/,
		'PNG'	=> qr/^\x89PNG\x0d\x0a\x1a\x0a/,
		'SVG'	=> qr/^<\?xml/,
		'TIF'	=> qr/^MM\x00\x2a|^II\x2a\x00/,
		);		
	my ($fh, $head, $type);	
	if (-e $file ) 
	  {
		open($fh, '<', $file) or die $!;
		read($fh,$head,11);
		close($fh);
		
		for $type (keys %types) 
		  { return $type if ($head =~ m/$types{$type}/);	}
   	}
  return undef;
  }

