<?php
function ImageCreateFromBMP($filename) { 
    if (! $f1 = fopen($filename,"rb")) return FALSE; 
    $BMP['bits_per_pixel']=16;
    $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel']/8; 
    $BMP['bytes_per_pixel2'] = ceil($BMP['bytes_per_pixel']); 
    $BMP['decal'] = 240*220/4; 
    $BMP['decal'] -= floor(240*220/4); 
    $BMP['decal'] = 4-(4*$BMP['decal']); 
    if ($BMP['decal'] == 4) $BMP['decal'] = 0; 
 
 
    $IMG = fread($f1,220*240*2); 
    $VIDE = chr(0); 
 
    $res = imagecreatetruecolor(240,220); 
    $P = 0; 
    $Y = 220-1; 
    while ($Y >= 0) { 
        $X=0; 
        while ($X < 240) { 
                $COLOR = unpack("v",substr($IMG,$P,2)); 
                $blue  = ($COLOR[1] & 0x001f) << 3; 
                $green = ($COLOR[1] & 0x07e0) >> 3; 
                $red   = ($COLOR[1] & 0xf800) >> 8; 
                $COLOR[1] = $red * 65536 + $green * 256 + $blue; 
                imagesetpixel($res,$X,$Y,$COLOR[1]); 
 
            $X++; 
            $P += $BMP['bytes_per_pixel']; 
        } 
        $Y--; 
        $P+=$BMP['decal']; 
    } 
 
    fclose($f1); 
    return $res; 
} 
$im=ImageCreateFromBMP("bild.raw");



  $rReturnImage = imagecreatetruecolor ( 240, 220 ); 

  for ( $iX = 0; $iX < 240; $iX++ ) 
  { 
    $iYr = 0; 
    for ( $iY = ( 220 - 1 ); $iY >= 0; $iY-- ) 
    { 
      $iColorIndex = imagecolorat ( $im, $iX, $iY ); 
      imagesetpixel ( $rReturnImage, $iX, $iYr, $iColorIndex ); 

      $iYr++; 
    } 
  } 




header('Content-type: image/jpeg');
imagejpeg($rReturnImage, NULL, 75);
imagedestroy($im);
imagedestroy ( $rReturnImage ); 
?>