Skip to content

Commit 504133b

Browse files
committed
Add background images to slide layouts
1 parent 8b9167e commit 504133b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/PhpPresentation/Writer/PowerPoint2007/PptSlideLayouts.php

+16
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpOffice\PhpPresentation\Slide;
88
use PhpOffice\PhpPresentation\Slide\SlideLayout;
99
use PhpOffice\PhpPresentation\Style\ColorMap;
10+
use PhpOffice\PhpPresentation\Slide\Background\Image;
1011

1112
class PptSlideLayouts extends AbstractSlide
1213
{
@@ -20,6 +21,12 @@ public function render()
2021
foreach ($oSlideMaster->getAllSlideLayouts() as $oSlideLayout) {
2122
$this->oZip->addFromString('ppt/slideLayouts/_rels/slideLayout' . $oSlideLayout->layoutNr . '.xml.rels', $this->writeSlideLayoutRelationships($oSlideLayout));
2223
$this->oZip->addFromString('ppt/slideLayouts/slideLayout' . $oSlideLayout->layoutNr . '.xml', $this->writeSlideLayout($oSlideLayout));
24+
25+
// Add background image slide
26+
$oBkgImage = $oSlideLayout->getBackground();
27+
if ($oBkgImage instanceof Image) {
28+
$this->oZip->addFromString('ppt/media/' . $oBkgImage->getIndexedFilename($oSlideLayout->getRelsIndex()), file_get_contents($oBkgImage->getPath()));
29+
}
2330
}
2431
}
2532

@@ -53,6 +60,15 @@ public function writeSlideLayoutRelationships(SlideLayout $oSlideLayout)
5360
// Write drawing relationships?
5461
$relId = $this->writeDrawingRelations($oSlideLayout, $objWriter, ++$relId);
5562

63+
// Write background relationships?
64+
$oBackground = $oSlideLayout->getBackground();
65+
if ($oBackground instanceof Image) {
66+
$this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($oSlideLayout->getRelsIndex()));
67+
$oBackground->relationId = 'rId' . $relId;
68+
69+
$relId++;
70+
}
71+
5672
$objWriter->endElement();
5773

5874
// Return

0 commit comments

Comments
 (0)