Skip to content

Commit aeb09c5

Browse files
author
Peter Lind
committed
fixing issue #330: background images do not work for master slides
1 parent 312b7a2 commit aeb09c5

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/PhpPresentation/Writer/PowerPoint2007/PptSlideMasters.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PhpOffice\PhpPresentation\Slide;
1212
use PhpOffice\PhpPresentation\Slide\SlideMaster;
1313
use PhpOffice\PhpPresentation\Style\SchemeColor;
14+
use PhpOffice\PhpPresentation\Slide\Background\Image;
1415

1516
class PptSlideMasters extends AbstractSlide
1617
{
@@ -24,6 +25,13 @@ public function render()
2425
$this->oZip->addFromString('ppt/slideMasters/_rels/slideMaster' . $oMasterSlide->getRelsIndex() . '.xml.rels', $this->writeSlideMasterRelationships($oMasterSlide));
2526
// Add the information from the masterSlide to the ZIP file
2627
$this->oZip->addFromString('ppt/slideMasters/slideMaster' . $oMasterSlide->getRelsIndex() . '.xml', $this->writeSlideMaster($oMasterSlide));
28+
29+
// Add background image slide
30+
$oBkgImage = $oMasterSlide->getBackground();
31+
if ($oBkgImage instanceof Image) {
32+
$this->oZip->addFromString('ppt/media/' . $oBkgImage->getIndexedFilename($oMasterSlide->getRelsIndex()), file_get_contents($oBkgImage->getPath()));
33+
}
34+
2735
}
2836

2937
return $this->oZip;
@@ -55,7 +63,16 @@ public function writeSlideMasterRelationships(SlideMaster $oMasterSlide)
5563
$slideLayout->relationId = 'rId' . $relId;
5664
}
5765
// Write drawing relationships?
66+
5867
$this->writeDrawingRelations($oMasterSlide, $objWriter, $relId);
68+
69+
// Write background relationships?
70+
$oBackground = $oMasterSlide->getBackground();
71+
if ($oBackground instanceof Image) {
72+
$this->writeRelationship($objWriter, ++$relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($oMasterSlide->getRelsIndex()));
73+
$oBackground->relationId = 'rId' . $relId;
74+
}
75+
5976
// TODO: Write hyperlink relationships?
6077
// TODO: Write comment relationships
6178
// Relationship theme/theme1.xml

0 commit comments

Comments
 (0)