You are here

private function PHPExcel_Reader_Excel5::_readImData in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php \PHPExcel_Reader_Excel5::_readImData()

* Read IMDATA record

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Reader/Excel5.php, line 5039

Class

PHPExcel_Reader_Excel5
PHPExcel_Reader_Excel5

Code

private function _readImData() {
  $length = self::_GetInt2d($this->_data, $this->_pos + 2);

  // get spliced record data
  $splicedRecordData = $this
    ->_getSplicedRecordData();
  $recordData = $splicedRecordData['recordData'];

  // UNDER CONSTRUCTION
  // offset: 0; size: 2; image format
  $cf = self::_GetInt2d($recordData, 0);

  // offset: 2; size: 2; environment from which the file was written
  $env = self::_GetInt2d($recordData, 2);

  // offset: 4; size: 4; length of the image data
  $lcb = self::_GetInt4d($recordData, 4);

  // offset: 8; size: var; image data
  $iData = substr($recordData, 8);
  switch ($cf) {
    case 0x9:

      // Windows bitmap format
      // BITMAPCOREINFO
      // 1. BITMAPCOREHEADER
      // offset: 0; size: 4; bcSize, Specifies the number of bytes required by the structure
      $bcSize = self::_GetInt4d($iData, 0);

      //			var_dump($bcSize);
      // offset: 4; size: 2; bcWidth, specifies the width of the bitmap, in pixels
      $bcWidth = self::_GetInt2d($iData, 4);

      //			var_dump($bcWidth);
      // offset: 6; size: 2; bcHeight, specifies the height of the bitmap, in pixels.
      $bcHeight = self::_GetInt2d($iData, 6);

      //			var_dump($bcHeight);
      $ih = imagecreatetruecolor($bcWidth, $bcHeight);

      // offset: 8; size: 2; bcPlanes, specifies the number of planes for the target device. This value must be 1
      // offset: 10; size: 2; bcBitCount specifies the number of bits-per-pixel. This value must be 1, 4, 8, or 24
      $bcBitCount = self::_GetInt2d($iData, 10);

      //			var_dump($bcBitCount);
      $rgbString = substr($iData, 12);
      $rgbTriples = array();
      while (strlen($rgbString) > 0) {
        $rgbTriples[] = unpack('Cb/Cg/Cr', $rgbString);
        $rgbString = substr($rgbString, 3);
      }
      $x = 0;
      $y = 0;
      foreach ($rgbTriples as $i => $rgbTriple) {
        $color = imagecolorallocate($ih, $rgbTriple['r'], $rgbTriple['g'], $rgbTriple['b']);
        imagesetpixel($ih, $x, $bcHeight - 1 - $y, $color);
        $x = ($x + 1) % $bcWidth;
        $y = $y + floor(($x + 1) / $bcWidth);
      }

      //imagepng($ih, 'image.png');
      $drawing = new PHPExcel_Worksheet_Drawing();
      $drawing
        ->setPath($filename);
      $drawing
        ->setWorksheet($this->_phpSheet);
      break;
    case 0x2:

    // Windows metafile or Macintosh PICT format
    case 0xe:

    // native format
    default:
      break;
  }

  // _getSplicedRecordData() takes care of moving current position in data stream
}