|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpPresentation\Writer\ODPresentation; |
|
4
|
|
|
|
|
5
|
|
|
use PhpOffice\Common\Adapter\Zip\ZipInterface; |
|
6
|
|
|
use PhpOffice\PhpPresentation\Shape\Drawing; |
|
7
|
|
|
use PhpOffice\PhpPresentation\Shape\MemoryDrawing; |
|
8
|
|
|
use PhpOffice\PhpPresentation\Slide\Background\Image; |
|
9
|
|
|
|
|
10
|
|
|
class Pictures extends AbstractDecoratorWriter |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @return ZipInterface |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
55 |
|
public function render() |
|
17
|
|
|
{ |
|
18
|
55 |
|
$arrMedia = array(); |
|
19
|
55 |
|
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) { |
|
20
|
27 |
|
$shape = $this->getDrawingHashTable()->getByIndex($i); |
|
21
|
27 |
|
if ($shape instanceof Drawing) { |
|
22
|
6 |
|
if (!in_array(md5($shape->getPath()), $arrMedia)) { |
|
23
|
6 |
|
$arrMedia[] = md5($shape->getPath()); |
|
24
|
|
|
|
|
25
|
6 |
|
$imagePath = $shape->getPath(); |
|
26
|
|
|
|
|
27
|
6 |
|
if (strpos($imagePath, 'zip://') !== false) { |
|
28
|
1 |
|
$imagePath = substr($imagePath, 6); |
|
29
|
1 |
|
$imagePathSplitted = explode('#', $imagePath); |
|
30
|
|
|
|
|
31
|
1 |
|
$imageZip = new \ZipArchive(); |
|
32
|
1 |
|
$imageZip->open($imagePathSplitted[0]); |
|
33
|
1 |
|
$imageContents = $imageZip->getFromName($imagePathSplitted[1]); |
|
34
|
1 |
|
$imageZip->close(); |
|
35
|
1 |
|
unset($imageZip); |
|
36
|
6 |
|
} elseif (strpos($imagePath, 'data:image/') === 0) { |
|
37
|
1 |
|
list(, $imageContents) = explode(';', $imagePath); |
|
38
|
1 |
|
list(, $imageContents) = explode(',', $imageContents); |
|
39
|
1 |
|
$imageContents = base64_decode($imageContents); |
|
40
|
1 |
|
} else { |
|
41
|
4 |
|
$imageContents = file_get_contents($imagePath); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
6 |
|
$this->getZip()->addFromString('Pictures/' . md5($shape->getPath()).'.'.$shape->getExtension(), $imageContents); |
|
45
|
6 |
|
} |
|
46
|
27 |
|
} elseif ($shape instanceof MemoryDrawing) { |
|
47
|
1 |
|
if (!in_array(str_replace(' ', '_', $shape->getIndexedFilename()), $arrMedia)) { |
|
48
|
1 |
|
$arrMedia[] = str_replace(' ', '_', $shape->getIndexedFilename()); |
|
49
|
1 |
|
ob_start(); |
|
50
|
1 |
|
call_user_func($shape->getRenderingFunction(), $shape->getImageResource()); |
|
51
|
1 |
|
$imageContents = ob_get_contents(); |
|
52
|
1 |
|
ob_end_clean(); |
|
53
|
|
|
|
|
54
|
1 |
|
$this->getZip()->addFromString('Pictures/' . str_replace(' ', '_', $shape->getIndexedFilename()), $imageContents); |
|
55
|
1 |
|
} |
|
56
|
1 |
|
} |
|
57
|
27 |
|
} |
|
58
|
|
|
|
|
59
|
55 |
|
foreach ($this->getPresentation()->getAllSlides() as $keySlide => $oSlide) { |
|
60
|
|
|
// Add background image slide |
|
61
|
55 |
|
$oBkgImage = $oSlide->getBackground(); |
|
62
|
55 |
|
if ($oBkgImage instanceof Image) { |
|
63
|
1 |
|
$this->getZip()->addFromString('Pictures/'.$oBkgImage->getIndexedFilename($keySlide), file_get_contents($oBkgImage->getPath())); |
|
64
|
1 |
|
} |
|
65
|
55 |
|
} |
|
66
|
|
|
|
|
67
|
55 |
|
return $this->getZip(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|