Skip to content

Commit 30a3fc8

Browse files
committed
Merge pull request #183 from Progi1984/issue125
#125 : PR
2 parents 9727408 + 915be63 commit 30a3fc8

File tree

16 files changed

+377
-69
lines changed

16 files changed

+377
-69
lines changed

docs/general.rst

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Document information
5353
--------------------
5454

5555
You can set the document information such as title, creator, and company
56-
name. Use the following functions:
56+
name. Use the following functions :
5757

5858
.. code-block:: php
5959
@@ -69,3 +69,37 @@ name. Use the following functions:
6969
$properties->setSubject('My subject');
7070
$properties->setKeywords('my, key, word');
7171
72+
73+
Presentation Properties
74+
-----------------------
75+
76+
You can define some properties which are relative to the presentation, like the zoom or the thumbnail.
77+
78+
79+
Thumbnail
80+
`````````
81+
82+
You can define the thumbnail of the presentation with the method ``setThumbnailPath``.
83+
84+
.. code-block:: php
85+
86+
$oPresentation = new PhpPresentation();
87+
$oProperties = $oPresentation->getPresentationProperties();
88+
// Set path of the thumbnail
89+
$oProperties->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
90+
// Get path of the thumbnail
91+
echo $oProperties->getThumbnailPath();
92+
93+
Zoom
94+
````
95+
96+
You can define the zoom of the presentation with the method ``setZoom``.
97+
98+
.. code-block:: php
99+
100+
$oPresentation = new PhpPresentation();
101+
$oProperties = $oPresentation->getPresentationProperties();
102+
// Set zoom of the presentation (3 = 300%)
103+
$oProperties->setZoom(3);
104+
// Get zoom of the presentation
105+
echo $oProperties->getZoom();

samples/Sample_14_Zoom.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
$objPHPPresentation = new PhpPresentation();
1212

1313
// Set the zoom to 200%
14-
$objPHPPresentation->setZoom(3);
14+
$objPHPPresentation->getPresentationProperties()->setZoom(3);
1515

1616
// Create slide
1717
echo date('H:i:s') . ' Create slide'.EOL;

samples/Sample_16_Thumbnail.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
include_once 'Sample_Header.php';
4+
5+
use PhpOffice\PhpPresentation\PhpPresentation;
6+
use PhpOffice\PhpPresentation\Slide\Background\Color;
7+
use PhpOffice\PhpPresentation\Style\Color as StyleColor;
8+
use \PhpOffice\PhpPresentation\Slide\Background\Image;
9+
10+
// Create new PHPPresentation object
11+
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
12+
$objPHPPresentation = new PhpPresentation();
13+
14+
// Set Thumbnail
15+
$objPHPPresentation->getPresentationProperties()->setThumbnailPath(__DIR__.'\resources\phppowerpoint_logo.gif');
16+
17+
// Create slide
18+
echo date('H:i:s') . ' Create slide'.EOL;
19+
$oSlide1 = $objPHPPresentation->getActiveSlide();
20+
$oSlide1->addShape(clone $oShapeDrawing);
21+
$oSlide1->addShape(clone $oShapeRichText);
22+
23+
// Save file
24+
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
25+
if (!CLI) {
26+
include_once 'Sample_Footer.php';
27+
}

src/PhpPresentation/PhpPresentation.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,6 @@ class PhpPresentation
6060
*/
6161
private $activeSlideIndex = 0;
6262

63-
/**
64-
* Mark as final
65-
* @var bool
66-
*/
67-
private $markAsFinal = false;
68-
69-
/**
70-
* Zoom
71-
* @var float
72-
*/
73-
private $zoom = 1;
74-
7563
/**
7664
* Create a new PhpPresentation with one Slide
7765
*/
@@ -361,43 +349,41 @@ public function copy()
361349
* Mark a document as final
362350
* @param bool $state
363351
* @return PhpPresentation
352+
* @deprecated for getPresentationProperties()->markAsFinal()
364353
*/
365354
public function markAsFinal($state = true)
366355
{
367-
if (is_bool($state)) {
368-
$this->markAsFinal = $state;
369-
}
370-
return $this;
356+
return $this->getPresentationProperties()->markAsFinal($state);
371357
}
372358

373359
/**
374360
* Return if this document is marked as final
375361
* @return bool
362+
* @deprecated for getPresentationProperties()->isMarkedAsFinal()
376363
*/
377364
public function isMarkedAsFinal()
378365
{
379-
return $this->markAsFinal;
366+
return $this->getPresentationProperties()->isMarkedAsFinal();
380367
}
381368

382369
/**
383370
* Set the zoom of the document (in percentage)
384371
* @param float $zoom
385372
* @return PhpPresentation
373+
* @deprecated for getPresentationProperties()->setZoom()
386374
*/
387375
public function setZoom($zoom = 1)
388376
{
389-
if (is_numeric($zoom)) {
390-
$this->zoom = $zoom;
391-
}
392-
return $this;
377+
return $this->getPresentationProperties()->setZoom($zoom);
393378
}
394379

395380
/**
396381
* Return the zoom (in percentage)
397382
* @return float
383+
* @deprecated for getPresentationProperties()->getZoom()
398384
*/
399385
public function getZoom()
400386
{
401-
return $this->zoom;
387+
return $this->getPresentationProperties()->getZoom();
402388
}
403389
}

src/PhpPresentation/PresentationProperties.php

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ class PresentationProperties
2525
* @var boolean
2626
*/
2727
protected $isLoopUntilEsc = false;
28+
29+
/**
30+
* Mark as final
31+
* @var bool
32+
*/
33+
protected $markAsFinal = false;
34+
35+
/*
36+
* @var string
37+
*/
38+
protected $thumbnail;
39+
40+
/**
41+
* Zoom
42+
* @var float
43+
*/
44+
protected $zoom = 1;
2845

2946
/**
3047
* @return bool
@@ -40,7 +57,75 @@ public function isLoopContinuouslyUntilEsc()
4057
*/
4158
public function setLoopContinuouslyUntilEsc($value = false)
4259
{
43-
$this->isLoopUntilEsc = $value;
60+
if (is_bool($value)) {
61+
$this->isLoopUntilEsc = $value;
62+
}
63+
return $this;
64+
}
65+
66+
/**
67+
* Return the thumbnail file path
68+
* @return string
69+
*/
70+
public function getThumbnailPath()
71+
{
72+
return $this->thumbnail;
73+
}
74+
75+
/**
76+
* Define the path for the thumbnail file / preview picture
77+
* @param string $value
78+
* @return \PhpOffice\PhpPresentation\PresentationProperties
79+
*/
80+
public function setThumbnailPath($path = '')
81+
{
82+
if (file_exists($path)) {
83+
$this->thumbnail = $path;
84+
}
85+
return $this;
86+
}
87+
88+
/**
89+
* Mark a document as final
90+
* @param bool $state
91+
* @return PhpPresentation
92+
*/
93+
public function markAsFinal($state = true)
94+
{
95+
if (is_bool($state)) {
96+
$this->markAsFinal = $state;
97+
}
98+
return $this;
99+
}
100+
101+
/**
102+
* Return if this document is marked as final
103+
* @return bool
104+
*/
105+
public function isMarkedAsFinal()
106+
{
107+
return $this->markAsFinal;
108+
}
109+
110+
/**
111+
* Set the zoom of the document (in percentage)
112+
* @param float $zoom
113+
* @return PhpPresentation
114+
*/
115+
public function setZoom($zoom = 1)
116+
{
117+
if (is_numeric($zoom)) {
118+
$this->zoom = $zoom;
119+
}
44120
return $this;
45121
}
122+
123+
/**
124+
* Return the zoom (in percentage)
125+
* @return float
126+
*/
127+
public function getZoom()
128+
{
129+
return $this->zoom;
130+
}
46131
}

src/PhpPresentation/Writer/ODPresentation.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,35 @@ public function save($pFilename)
185185

186186
// Add META-INF/manifest.xml
187187
$objZip->addFromString('META-INF/manifest.xml', $writerPartManifest->writePart());
188+
189+
// Add Thumbnail
190+
if ($this->presentation->getPresentationProperties()->getThumbnailPath()) {
191+
$pathThumbnail = $this->presentation->getPresentationProperties()->getThumbnailPath();
192+
// Size : 128x128 pixel
193+
// PNG : 8bit, non-interlaced with full alpha transparency
194+
$gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
195+
if ($gdImage) {
196+
list($width, $height) = getimagesize($pathThumbnail);
197+
198+
$gdRender = imagecreatetruecolor(128, 128);
199+
$colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
200+
imagecolortransparent($gdRender, $colorBgAlpha);
201+
imagefill($gdRender, 0, 0, $colorBgAlpha);
202+
imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
203+
imagetruecolortopalette($gdRender, false, 255);
204+
imagesavealpha($gdRender, true);
205+
206+
ob_start();
207+
imagepng($gdRender);
208+
$imageContents = ob_get_contents();
209+
ob_end_clean();
210+
211+
imagedestroy($gdRender);
212+
imagedestroy($gdImage);
213+
214+
$objZip->addFromString('Thumbnails/thumbnail.png', $imageContents);
215+
}
216+
}
188217

189218
// Add charts
190219
foreach ($this->chartArray as $keyChart => $shapeChart) {

src/PhpPresentation/Writer/ODPresentation/Manifest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,20 @@ public function writePart()
125125
}
126126
}
127127

128+
if ($parentWriter->getPhpPresentation()->getPresentationProperties()->getThumbnailPath()) {
129+
$pathThumbnail = $parentWriter->getPhpPresentation()->getPresentationProperties()->getThumbnailPath();
130+
// Size : 128x128 pixel
131+
// PNG : 8bit, non-interlaced with full alpha transparency
132+
$gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
133+
if ($gdImage) {
134+
imagedestroy($gdImage);
135+
$objWriter->startElement('manifest:file-entry');
136+
$objWriter->writeAttribute('manifest:media-type', 'image/png');
137+
$objWriter->writeAttribute('manifest:full-path', 'Thumbnails/thumbnail.png');
138+
$objWriter->endElement();
139+
}
140+
}
141+
128142
$objWriter->endElement();
129143

130144
// Return

src/PhpPresentation/Writer/PowerPoint2007.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,27 @@ public function save($pFilename)
220220
$objZip->addFromString('ppt/viewProps.xml', $wPptProps->writeViewProps($this->presentation));
221221

222222
// Add relationships to ZIP file
223-
$objZip->addFromString('_rels/.rels', $wPartRels->writeRelationships());
223+
$objZip->addFromString('_rels/.rels', $wPartRels->writeRelationships($this->presentation));
224224
$objZip->addFromString('ppt/_rels/presentation.xml.rels', $wPartRels->writePresentationRelationships($this->presentation));
225225

226226
// Add document properties to ZIP file
227227
$objZip->addFromString('docProps/app.xml', $wPartDocProps->writeDocPropsApp($this->presentation));
228228
$objZip->addFromString('docProps/core.xml', $wPartDocProps->writeDocPropsCore($this->presentation));
229229
$objZip->addFromString('docProps/custom.xml', $wPartDocProps->writeDocPropsCustom($this->presentation));
230+
// Add Thumbnail to ZIP file
231+
if ($this->presentation->getPresentationProperties()->getThumbnailPath()) {
232+
$pathThumbnail = file_get_contents($this->presentation->getPresentationProperties()->getThumbnailPath());
233+
$gdImage = imagecreatefromstring($pathThumbnail);
234+
if ($gdImage) {
235+
ob_start();
236+
imagejpeg($gdImage);
237+
$imageContents = ob_get_contents();
238+
ob_end_clean();
239+
imagedestroy($gdImage);
240+
241+
$objZip->addFromString('docProps/thumbnail.jpeg', $imageContents);
242+
}
243+
}
230244

231245
$masterSlides = $this->getLayoutPack()->getMasterSlides();
232246
foreach ($masterSlides as $masterSlide) {

0 commit comments

Comments
 (0)