27
27
use PhpOffice \PhpWord \Style ;
28
28
use PhpOffice \PhpWord \Style \Font ;
29
29
use PhpOffice \PhpWord \Style \Paragraph ;
30
- use PhpOffice \PhpWord \TOC ;
31
30
32
31
/**
33
32
* HTML writer
@@ -170,10 +169,10 @@ private function writeHTMLBody()
170
169
$ html .= $ this ->writeImage ($ element );
171
170
} elseif ($ element instanceof Object) {
172
171
$ html .= $ this ->writeObject ($ element );
173
- } elseif ($ element instanceof Footnote) {
174
- $ html .= $ this ->writeFootnote ($ element );
175
172
} elseif ($ element instanceof Endnote) {
176
173
$ html .= $ this ->writeEndnote ($ element );
174
+ } elseif ($ element instanceof Footnote) {
175
+ $ html .= $ this ->writeFootnote ($ element );
177
176
}
178
177
}
179
178
}
@@ -257,10 +256,10 @@ private function writeTextRun($textrun)
257
256
$ html .= $ this ->writeTextBreak ($ element , true );
258
257
} elseif ($ element instanceof Image) {
259
258
$ html .= $ this ->writeImage ($ element , true );
260
- } elseif ($ element instanceof Footnote) {
261
- $ html .= $ this ->writeFootnote ($ element );
262
259
} elseif ($ element instanceof Endnote) {
263
260
$ html .= $ this ->writeEndnote ($ element );
261
+ } elseif ($ element instanceof Footnote) {
262
+ $ html .= $ this ->writeFootnote ($ element );
264
263
}
265
264
}
266
265
$ html .= '</p> ' . PHP_EOL ;
@@ -402,10 +401,10 @@ private function writeTable($element)
402
401
$ html .= $ this ->writeImage ($ content );
403
402
} elseif ($ content instanceof Object) {
404
403
$ html .= $ this ->writeObject ($ content );
405
- } elseif ($ element instanceof Footnote) {
406
- $ html .= $ this ->writeFootnote ($ element );
407
404
} elseif ($ element instanceof Endnote) {
408
405
$ html .= $ this ->writeEndnote ($ element );
406
+ } elseif ($ element instanceof Footnote) {
407
+ $ html .= $ this ->writeFootnote ($ element );
409
408
}
410
409
}
411
410
} else {
@@ -434,9 +433,13 @@ private function writeImage($element, $withoutP = false)
434
433
if (!$ this ->isPdf ) {
435
434
$ imageData = $ this ->getBase64ImageData ($ element );
436
435
if (!is_null ($ imageData )) {
437
- $ html = '<img border="0" src=" ' . $ imageData . '"/> ' ;
436
+ $ style = $ this ->assembleCss (array (
437
+ 'width ' => $ element ->getStyle ()->getWidth () . 'px ' ,
438
+ 'height ' => $ element ->getStyle ()->getHeight () . 'px ' ,
439
+ ));
440
+ $ html = "<img border= \"0 \" style= \"{$ style }\" src= \"{$ imageData }\"/> " ;
438
441
if (!$ withoutP ) {
439
- $ html = ' <p> ' . $ html . ' </p> ' . PHP_EOL ;
442
+ $ html = " <p> { $ html} </p> " . PHP_EOL ;
440
443
}
441
444
}
442
445
}
@@ -626,11 +629,12 @@ private function assembleCss($css, $curlyBracket = false)
626
629
private function getBase64ImageData (Image $ element )
627
630
{
628
631
$ imageData = null ;
632
+ $ imageBinary = null ;
629
633
$ source = $ element ->getSource ();
630
634
$ imageType = $ element ->getImageType ();
631
635
632
- // Get actual source
633
- if ($ element ->getSourceType () == ' archive ' ) {
636
+ // Get actual source from archive image
637
+ if ($ element ->getSourceType () == Image:: SOURCE_ARCHIVE ) {
634
638
$ source = substr ($ source , 6 );
635
639
list ($ zipFilename , $ imageFilename ) = explode ('# ' , $ source );
636
640
$ zip = new \ZipArchive ();
@@ -646,10 +650,20 @@ private function getBase64ImageData(Image $element)
646
650
}
647
651
648
652
// Read image binary data and convert into Base64
649
- if ($ fp = fopen ($ actualSource , "rb " , 0 )) {
650
- $ image = fread ($ fp , filesize ($ actualSource ));
651
- fclose ($ fp );
652
- $ base64 = chunk_split (base64_encode ($ image ));
653
+ if ($ element ->getSourceType () == Image::SOURCE_GD ) {
654
+ $ imageResource = call_user_func ($ element ->getImageCreateFunction (), $ actualSource );
655
+ ob_start ();
656
+ call_user_func ($ element ->getImageFunction (), $ imageResource );
657
+ $ imageBinary = ob_get_contents ();
658
+ ob_end_clean ();
659
+ } else {
660
+ if ($ fp = fopen ($ actualSource , 'rb ' , false )) {
661
+ $ imageBinary = fread ($ fp , filesize ($ actualSource ));
662
+ fclose ($ fp );
663
+ }
664
+ }
665
+ if (!is_null ($ imageBinary )) {
666
+ $ base64 = chunk_split (base64_encode ($ imageBinary ));
653
667
$ imageData = 'data: ' . $ imageType . ';base64, ' . $ base64 ;
654
668
}
655
669
0 commit comments