You are here

private function PHPExcel_Writer_HTML::_writeImageInCell in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php \PHPExcel_Writer_HTML::_writeImageInCell()

* Generate image tag in cell * *

Parameters

PHPExcel_Worksheet $pSheet PHPExcel_Worksheet: * @param string $coordinates Cell coordinates * @return string * @throws PHPExcel_Writer_Exception

2 calls to PHPExcel_Writer_HTML::_writeImageInCell()
PHPExcel_Writer_HTML::_extendRowsForChartsAndImages in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
PHPExcel_Writer_HTML::_generateRow in vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php
* Generate row * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/HTML.php, line 569

Class

PHPExcel_Writer_HTML
PHPExcel_Writer_HTML

Code

private function _writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) {

  // Construct HTML
  $html = '';

  // Write images
  foreach ($pSheet
    ->getDrawingCollection() as $drawing) {
    if ($drawing instanceof PHPExcel_Worksheet_Drawing) {
      if ($drawing
        ->getCoordinates() == $coordinates) {
        $filename = $drawing
          ->getPath();

        // Strip off eventual '.'
        if (substr($filename, 0, 1) == '.') {
          $filename = substr($filename, 1);
        }

        // Prepend images root
        $filename = $this
          ->getImagesRoot() . $filename;

        // Strip off eventual '.'
        if (substr($filename, 0, 1) == '.' && substr($filename, 0, 2) != './') {
          $filename = substr($filename, 1);
        }

        // Convert UTF8 data to PCDATA
        $filename = htmlspecialchars($filename);
        $html .= PHP_EOL;
        if (!$this->_embedImages || $this->_isPdf) {
          $imageData = $filename;
        }
        else {
          $imageDetails = getimagesize($filename);
          if ($fp = fopen($filename, "rb", 0)) {
            $picture = fread($fp, filesize($filename));
            fclose($fp);

            // base64 encode the binary data, then break it
            // into chunks according to RFC 2045 semantics
            $base64 = chunk_split(base64_encode($picture));
            $imageData = 'data:' . $imageDetails['mime'] . ';base64,' . $base64;
          }
          else {
            $imageData = $filename;
          }
        }
        $html .= '<div style="position: relative;">';
        $html .= '<img style="position: absolute; z-index: 1; left: ' . $drawing
          ->getOffsetX() . 'px; top: ' . $drawing
          ->getOffsetY() . 'px; width: ' . $drawing
          ->getWidth() . 'px; height: ' . $drawing
          ->getHeight() . 'px;" src="' . $imageData . '" border="0" />';
        $html .= '</div>';
      }
    }
  }

  // Return
  return $html;
}