Skip to content

Commit 58ec68a

Browse files
author
Phil Wilkinson
committed
ODPresentation - load images/resources to disk instead of loading into memory
1 parent a8cc93a commit 58ec68a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/PhpPresentation/Reader/ODPresentation.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,14 @@ protected function loadStyle(DOMElement $nodeStyle): bool
270270
if ('bitmap' == $nodeDrawingPageProps->getAttribute('draw:fill') && $nodeDrawingPageProps->hasAttribute('draw:fill-image-name')) {
271271
$nameStyle = $nodeDrawingPageProps->getAttribute('draw:fill-image-name');
272272
if (!empty($this->arrayCommonStyles[$nameStyle]) && 'image' == $this->arrayCommonStyles[$nameStyle]['type'] && !empty($this->arrayCommonStyles[$nameStyle]['path'])) {
273-
$tmpBkgImg = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderODPBkg');
274273
$contentImg = $this->oZip->getFromName($this->arrayCommonStyles[$nameStyle]['path']);
275-
file_put_contents($tmpBkgImg, $contentImg);
274+
if ($contentImg) {
275+
$tmpFile = new Gd();
276+
$tmpFile->loadFromContent($contentImg, basename($this->arrayCommonStyles[$nameStyle]['path']));
276277

277-
$oBackground = new Image();
278-
$oBackground->setPath($tmpBkgImg);
278+
$oBackground = new Image();
279+
$oBackground->setImage($tmpFile);
280+
}
279281
}
280282
}
281283
}
@@ -584,7 +586,7 @@ protected function loadShapeDrawing(DOMElement $oNodeFrame): void
584586
// Contents of file
585587
if (empty($mimetype)) {
586588
$shape = new Gd();
587-
$shape->setImageResource(imagecreatefromstring($imageFile));
589+
$shape->loadFromContent($imageFile, basename($sFilename));
588590
} else {
589591
$shape = new Base64();
590592
$shape->setData('data:' . $mimetype . ';base64,' . base64_encode($imageFile));
@@ -668,13 +670,12 @@ protected function loadShapeMedia(DOMElement $oNodeFrame): void
668670
$mediaFile = $this->oZip->getFromName($filePath);
669671
}
670672

671-
$tmpEmbed = tempnam(sys_get_temp_dir(), 'PhpPresentationReaderODPEmbed');
672-
file_put_contents($tmpEmbed, $mediaFile);
673+
if (!$mediaFile) {
674+
return;
675+
}
673676

674677
$shape = new Media();
675-
$shape
676-
->setFileName(basename($filePath))
677-
->setPath($tmpEmbed, false);
678+
$shape->loadFromContent($mediaFile, basename($filePath));
678679

679680
$shape->getShadow()->setVisible(false);
680681
$shape->setName($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : '');

0 commit comments

Comments
 (0)