Skip to content
This repository was archived by the owner on Jan 2, 2019. It is now read-only.

Convert PHPExcel_Worksheet_MemoryDrawing to inline image in HTML writer #209

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions Classes/PHPExcel/Writer/HTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,9 @@ private function _writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) {

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

// Strip off eventual '.'
Expand All @@ -590,7 +591,6 @@ private function _writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) {
// Convert UTF8 data to PCDATA
$filename = htmlspecialchars($filename);

$html .= PHP_EOL;
if ((!$this->_embedImages) || ($this->_isPdf)) {
$imageData = $filename;
} else {
Expand All @@ -607,6 +607,21 @@ private function _writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates) {
}
}

}
else if ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
ob_start();
call_user_func($drawing->getRenderingFunction(), $drawing->getImageResource());
$data = ob_get_contents();
ob_end_clean();

// base64 encode the binary data, then break it
// into chunks according to RFC 2045 semantics
$base64 = chunk_split(base64_encode($data));
$imageData = 'data:'.$drawing->getMimeType().';base64,' . $base64;
}

if ($imageData) {
$html .= PHP_EOL;
$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" />' . PHP_EOL;
$html .= '</div>';
Expand Down