#*****************************************************************#
  # ALLGEMEIN:                                                      #
  # Bildgröße ermitteln                                             #
  #*****************************************************************#
  
  use includedatei;

  $PFAD  = '/home/www/web0/html/bild/';
  $BILD  = 'hallo.gif';

  # Bildformat anhand der Dateierweitung

  @EXT = (split(/\./, $BILD));

  if ($EXT[1] eq "gif") {
    open (GIF , "<$PFAD.$BILD") ;
    undef $/;
    $gifs=<GIF> ;
    close(GIF) ;

    ($width,$height) = includedatei->gifsize($gifs) ;
  }
  elsif ($EXT[1] eq "jpg") {
    open (JPG , "<$PFAD.$BILD") ;
    undef $/;
    $jpg=<JPG> ;
    close(JPG) ;

    ($width,$height) = includedatei->jpegsize($jpg) ;
  }
  elsif ($EXT[1] eq "png") {
    open (PNG , "<$PFAD.$BILD") ;
    undef $/;
    $PNG=<PNG> ;
    close(PNG) ;

    ($width,$height) = includedatei->pngsize($PNG) ;
  }

  
  #*****************************************************************#
  # Subroutinen                                                     #
  #*****************************************************************#  
  

  # Breite und Hoehe der GIF Datei ermitteln

  sub gifsize
  {
    my ($self, $GIF)=@_;
    my ($type,$a,$b,$c,$d,$s,$width,$height) ;

    $type=substr($GIF,0,6);
    if(!($type =~ m/GIF8[7,9]a/) || (length($s=substr($GIF, 6, 4))!=4) )
    {
      return;
    }
    ($a,$b,$c,$d)=unpack("C"x4,$s);

    $width= $b<&tlg;8|$a;
    $height= $d<<8|$c;
    return ($width,$height);
  }

  # Breite und Hoehe der JPG Datei ermitteln

  sub jpegsize
  {
    my ($self, $JPEG)=@_ ;
    my ($count)=2 ;
    my ($length)=length($JPEG) ;
    my ($ch)="" ;
    my ($c1,$c2,$a,$b,$c,$d,$width,$height) ;

    while (($ch ne "\xda") && ($count<$length))
    {
      while (($ch ne "\xff") && ($count<$length))
      {
        $ch=substr($JPEG,$count,1);
        $count++;
      }
      while (($ch eq "\xff") && ($count<$length))
      {
        $ch=substr($JPEG,$count,1);
        $count++;
      }
      if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3))
      {
        $count+=3;
        ($a,$b,$c,$d)=unpack("C"x4,substr($JPEG,$count,4));
        $width=$c<<8|$d;
        $height=$a<<8|$b;
        return($width,$height);
      }
      else
      {
        ($c1,$c2)= unpack("C"x2,substr($JPEG,$count,2));
        $count += $c1<<8|$c2;
      }
    }
  }

  # Breite und Hoehe der PNG Datei ermitteln

  sub pngsize
  {
    my ($self, $BILD) = @_ ;
    my ($width,$height) = ( undef, undef );

    if ($BILD =~ /IHDR(.{8})/)
    {
       my $PNG = $1;
      ($width,$height) = unpack( "NN", $PNG );
    }

    return ($width,$height);
  }