Skip to content

Commit 5764b5c

Browse files
committed
Merge pull request #209 from Progi1984/issue123
#123 : Support for Video
2 parents 74d0773 + 7636514 commit 5764b5c

File tree

18 files changed

+266
-30
lines changed

18 files changed

+266
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- ODPresentation & PowerPoint2007 & Serialized Writer : Support for Zip Adapter - @Progi1984 GH-176
2424
- ODPresentation & PowerPoint2007 Writer : language property to TextElement - @skrajewski & @Progi1984 GH-180
2525
- ODPresentation & PowerPoint2007 Writer : Add Font Support For Chart Axis - @jrking4 GH-186
26+
- ODPresentation & PowerPoint2007 Writer : Support for video - @Progi1984 GH-123
2627
- PowerPoint2007 Writer : Presentation with predefined View Type - @Progi1984 GH-120
2728

2829
## 0.6.0 - 2016-01-24

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ PHPPresentation is a library written in pure PHP that provides a set of classes
3434

3535
shapes_chart
3636
shapes_comment
37+
shapes_media
3738
shapes_richtext
3839
shapes_table
3940

docs/shapes.rst

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,11 @@ Example:
2727
->setOffsetX(170)
2828
->setOffsetY(180);
2929
30-
Rich text
31-
---------
32-
33-
The Rich text has :ref:`its own page <shapes_richtext>`.
34-
3530
Line
3631
----
3732

3833
To create a line, use `createLineShape` method of slide.
3934

40-
Chart
41-
-----
42-
43-
The Chart has :ref:`its own page <shapes_chart>`.
44-
45-
Comment
46-
-------
47-
48-
The Comment has :ref:`its own page <shapes_comment>`.
4935

5036
Drawing
5137
-------
@@ -58,8 +44,3 @@ To create a drawing, use `createDrawingShape` method of slide.
5844
$drawing->setName('Unique name')
5945
->setDescription('Description of the drawing')
6046
->setPath('/path/to/drawing.filename');
61-
62-
Table
63-
-----
64-
65-
The Table has :ref:`its own page <shapes_table>`.

docs/shapes_media.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.. _shapes_table:
2+
3+
Media
4+
=====
5+
6+
To create a video, create an object `Media`.
7+
8+
Example:
9+
10+
.. code-block:: php
11+
12+
use PhpOffice\PhpPresentation\Shape\Media;
13+
14+
$oMedia = new Media();
15+
$oMedia->setPath('file.mp4');
16+
// $oMedia->setPath('file.ogv');
17+
$oSlide->addShape($oMedia);
18+
19+
You can define text and date with setters.
20+
21+
Example:
22+
23+
.. code-block:: php
24+
25+
use PhpOffice\PhpPresentation\Shape\Media;
26+
27+
$oMedia = new Media();
28+
$oMedia->setName('Name of the Media');
29+
$oSlide->addShape($oMedia);
30+
31+
32+
Quirks
33+
------
34+
35+
For PowerPoint2007 Writer, the prefered file format is MP4.
36+
For ODPresentation Writer, the prefered file format is OGV.

samples/Sample_03_Image.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpOffice\PhpPresentation\PhpPresentation;
66
use PhpOffice\PhpPresentation\Shape\Drawing;
7+
use PhpOffice\PhpPresentation\Shape\Media;
78
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
89

910
// Create new PHPPresentation object
@@ -24,13 +25,13 @@
2425
echo date('H:i:s') . ' Add a drawing to the slide'.EOL;
2526
$shape = new MemoryDrawing();
2627
$shape->setName('Sample image')
27-
->setDescription('Sample image')
28-
->setImageResource($gdImage)
29-
->setRenderingFunction(MemoryDrawing::RENDERING_JPEG)
30-
->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT)
31-
->setHeight(36)
32-
->setOffsetX(10)
33-
->setOffsetY(10);
28+
->setDescription('Sample image')
29+
->setImageResource($gdImage)
30+
->setRenderingFunction(MemoryDrawing::RENDERING_JPEG)
31+
->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT)
32+
->setHeight(36)
33+
->setOffsetX(10)
34+
->setOffsetY(10);
3435
$currentSlide->addShape($shape);
3536

3637
// Add a file drawing (GIF) to the slide
@@ -55,6 +56,18 @@
5556
->setOffsetY(200);
5657
$currentSlide->addShape($shape);
5758

59+
// Add a video to the slide
60+
$shape = new Media();
61+
$shape->setName('Video')
62+
->setDescription('Video')
63+
->setPath(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? './resources/sintel_trailer-480p.mp4' : './resources/sintel_trailer-480p.ogv')
64+
->setResizeProportional(false)
65+
->setHeight(90)
66+
->setWidth(90)
67+
->setOffsetX(10)
68+
->setOffsetY(300);
69+
$currentSlide->addShape($shape);
70+
5871
// Save file
5972
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
6073
if (!CLI) {
4.17 MB
Binary file not shown.
12.4 MB
Binary file not shown.
-6.96 MB
Binary file not shown.

src/PhpPresentation/Shape/Media.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* This file is part of PHPPresentation - A pure PHP library for reading and writing
4+
* presentations documents.
5+
*
6+
* PHPPresentation is free software distributed under the terms of the GNU Lesser
7+
* General Public License version 3 as published by the Free Software Foundation.
8+
*
9+
* For the full copyright and license information, please read the LICENSE
10+
* file that was distributed with this source code. For the full list of
11+
* contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12+
*
13+
* @link https://github.com/PHPOffice/PHPPresentation
14+
* @copyright 2009-2015 PHPPresentation contributors
15+
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16+
*/
17+
18+
namespace PhpOffice\PhpPresentation\Shape;
19+
20+
use PhpOffice\PhpPresentation\ComparableInterface;
21+
22+
/**
23+
* Media element
24+
*/
25+
class Media extends Drawing implements ComparableInterface
26+
{
27+
}

src/PhpPresentation/Writer/ODPresentation.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,25 @@ public function save($pFilename)
9999
$oPresentation = $this->getPhpPresentation();
100100
$arrayChart = array();
101101

102+
$arrayFiles = array();
102103
$oDir = new DirectoryIterator(dirname(__FILE__).DIRECTORY_SEPARATOR.'ODPresentation');
103104
foreach ($oDir as $oFile) {
104105
if (!$oFile->isFile()) {
105106
continue;
106107
}
107-
$class = __NAMESPACE__.'\\ODPresentation\\'.$oFile->getBasename('.php');
108+
109+
$class = __NAMESPACE__ . '\\ODPresentation\\' . $oFile->getBasename('.php');
108110
$o = new \ReflectionClass($class);
109111

110112
if ($o->isAbstract() || !$o->isSubclassOf('PhpOffice\PhpPresentation\Writer\ODPresentation\AbstractDecoratorWriter')) {
111113
continue;
112114
}
115+
$arrayFiles[$oFile->getBasename('.php')] = $o;
116+
}
117+
118+
ksort($arrayFiles);
119+
120+
foreach ($arrayFiles as $o) {
113121
$oService = $o->newInstance();
114122
$oService->setZip($oZip);
115123
$oService->setPresentation($oPresentation);

0 commit comments

Comments
 (0)