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

Commit

Permalink
Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in…
Browse files Browse the repository at this point in the history
… HTML writer

Manual merge of Pull Request
  • Loading branch information
MarkBaker committed Mar 1, 2016
1 parent 352e6ea commit 39d8b8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions Classes/PHPExcel/Writer/HTML.php
Expand Up @@ -656,6 +656,22 @@ private function writeImageInCell(PHPExcel_Worksheet $pSheet, $coordinates)
$imageData . '" border="0" />';
$html .= '</div>';
}
} elseif ($drawing instanceof PHPExcel_Worksheet_MemoryDrawing) {
if ($drawing->getCoordinates() != $coordinates) {
continue;
}
ob_start(); // Let's start output buffering.
imagepng($drawing->getImageResource()); // This will normally output the image, but because of ob_start(), it won't.
$contents = ob_get_contents(); // Instead, output above is saved to $contents
ob_end_clean(); // End the output buffer.

$dataUri = "data:image/jpeg;base64," . base64_encode($contents);

// Because of the nature of tables, width is more important than height.
// max-width: 100% ensures that image doesnt overflow containing cell
// width: X sets width of supplied image.
// As a result, images bigger than cell will be contained and images smaller will not get stretched
$html .= '<img src="'.$dataUri.'" style="max-width:100%;width:'.$drawing->getWidth().'px;" />';
}
}

Expand Down
8 changes: 7 additions & 1 deletion Examples/25inmemoryimage.php
Expand Up @@ -75,9 +75,15 @@
echo date('H:i:s') , " File written to " , str_replace('.php', '.xlsx', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;


echo date('H:i:s') , " Write to HTML format" , EOL;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->save(str_replace('.php', '.html', __FILE__));
echo date('H:i:s') , " File written to " , str_replace('.php', '.html', pathinfo(__FILE__, PATHINFO_BASENAME)) , EOL;


// Echo memory peak usage
echo date('H:i:s') , " Peak memory usage: " , (memory_get_peak_usage(true) / 1024 / 1024) , " MB" , EOL;

// Echo done
echo date('H:i:s') , " Done writing file" , EOL;
echo 'File has been created in ' , getcwd() , EOL;
echo 'Files have been created in ' , getcwd() , EOL;
1 change: 1 addition & 0 deletions changelog.txt
Expand Up @@ -31,6 +31,7 @@ Planned for 1.8.2
- Bugfix: (MBaker) Work Item GH-554 - Whitespace after toRichTextObject()
- Feature: (MBaker) - Initial implementation of SUMIFS() function
- Feature: (MBaker) - Additional codepages
- Feature: (Tomino2112) Work Item GH-808 - MemoryDrawing not working in HTML writer


2015-04-30 (v1.8.1):
Expand Down

0 comments on commit 39d8b8f

Please sign in to comment.