Skip to content

Commit 86946f7

Browse files
committed
Merge pull request #207 from Progi1984/issue192
#192 : Image Adapter
2 parents ee07eb7 + c53e5e6 commit 86946f7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1055
-930
lines changed

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_drawing
3738
shapes_media
3839
shapes_richtext
3940
shapes_table

docs/shapes.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,3 @@ Line
3131
----
3232

3333
To create a line, use `createLineShape` method of slide.
34-
35-
36-
Drawing
37-
-------
38-
39-
To create a drawing, use `createDrawingShape` method of slide.
40-
41-
.. code-block:: php
42-
43-
$drawing = $slide->createDrawingShape();
44-
$drawing->setName('Unique name')
45-
->setDescription('Description of the drawing')
46-
->setPath('/path/to/drawing.filename');

docs/shapes_drawing.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. _shapes_drawing:
2+
3+
Drawing
4+
=======
5+
6+
To create a drawing, you have four sources : File, GD, Base64 and ZipFile.
7+
8+
File
9+
----
10+
11+
To create a drawing, use `createDrawingShape` method of slide.
12+
13+
.. code-block:: php
14+
15+
$oShape = $oSlide->createDrawingShape();
16+
$oShape->setName('Unique name')
17+
->setDescription('Description of the drawing')
18+
->setPath('/path/to/drawing.filename');
19+
20+
It's an alias for :
21+
22+
.. code-block:: php
23+
24+
use PhpOffice\PhpPresentation\Shape\Drawing\File;
25+
26+
$oShape = new File();
27+
$oShape->setName('Unique name')
28+
->setDescription('Description of the drawing')
29+
->setPath('/path/to/drawing.filename');
30+
$oSlide->addShape($oShape);
31+
32+
GD
33+
--
34+
35+
.. code-block:: php
36+
37+
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
38+
39+
$gdImage = @imagecreatetruecolor($width, $height);
40+
41+
$oShape = new Gd();
42+
$oShape->setName('Sample image')
43+
->setDescription('Sample image')
44+
->setImageResource($gdImage)
45+
->setRenderingFunction(Drawing\Gd::RENDERING_JPEG)
46+
->setMimeType(Drawing\Gd::MIMETYPE_DEFAULT);
47+
$oSlide->addShape($oShape);
48+
49+
50+
Base64
51+
------
52+
53+
.. code-block:: php
54+
55+
use PhpOffice\PhpPresentation\Shape\Drawing\Base64;
56+
57+
$oShape = new Base64();
58+
$oShape->setName('Sample image')
59+
->setDescription('Sample image')
60+
->setImageResource($gdImage)
61+
->setData('data:image/jpeg;base64,..........');
62+
$oSlide->addShape($oShape);
63+
64+
ZipFile
65+
-------
66+
67+
.. code-block:: php
68+
69+
use PhpOffice\PhpPresentation\Shape\Drawing\ZipFile;
70+
71+
$oShape = new ZipFile();
72+
$oShape->setName('Sample image')
73+
->setDescription('Sample image')
74+
->setPath('zip://myzipfile.zip#path/in/zip/img.ext')
75+
$oSlide->addShape($oShape);

docs/shapes_media.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Example:
1212
use PhpOffice\PhpPresentation\Shape\Media;
1313
1414
$oMedia = new Media();
15-
$oMedia->setPath('file.mp4');
15+
$oMedia->setPath('file.wmv');
1616
// $oMedia->setPath('file.ogv');
1717
$oSlide->addShape($oMedia);
1818
@@ -32,5 +32,5 @@ Example:
3232
Quirks
3333
------
3434

35-
For PowerPoint2007 Writer, the prefered file format is MP4.
36-
For ODPresentation Writer, the prefered file format is OGV.
35+
For Windows readers, the prefered file format is WMV.
36+
For Linux readers, the prefered file format is OGV.

samples/Sample_01_Simple.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,48 @@
1111
$objPHPPresentation = new PhpPresentation();
1212

1313
// Set properties
14-
echo date('H:i:s') . ' Set properties'.EOL;
15-
$objPHPPresentation->getProperties()->setCreator('PHPOffice')
16-
->setLastModifiedBy('PHPPresentation Team')
17-
->setTitle('Sample 01 Title')
18-
->setSubject('Sample 01 Subject')
19-
->setDescription('Sample 01 Description')
20-
->setKeywords('office 2007 openxml libreoffice odt php')
21-
->setCategory('Sample Category');
14+
echo date('H:i:s') . ' Set properties' . EOL;
15+
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
16+
->setLastModifiedBy('PHPPresentation Team')
17+
->setTitle('Sample 01 Title')
18+
->setSubject('Sample 01 Subject')
19+
->setDescription('Sample 01 Description')
20+
->setKeywords('office 2007 openxml libreoffice odt php')
21+
->setCategory('Sample Category');
2222

2323
// Create slide
24-
echo date('H:i:s') . ' Create slide'.EOL;
24+
echo date('H:i:s') . ' Create slide' . EOL;
2525
$currentSlide = $objPHPPresentation->getActiveSlide();
2626

2727
// Create a shape (drawing)
28-
echo date('H:i:s') . ' Create a shape (drawing)'.EOL;
28+
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
2929
$shape = $currentSlide->createDrawingShape();
3030
$shape->setName('PHPPresentation logo')
31-
->setDescription('PHPPresentation logo')
32-
->setPath('./resources/phppowerpoint_logo.gif')
33-
->setHeight(36)
34-
->setOffsetX(10)
35-
->setOffsetY(10);
31+
->setDescription('PHPPresentation logo')
32+
->setPath('./resources/phppowerpoint_logo.gif')
33+
->setHeight(36)
34+
->setOffsetX(10)
35+
->setOffsetY(10);
3636
$shape->getShadow()->setVisible(true)
37-
->setDirection(45)
38-
->setDistance(10);
37+
->setDirection(45)
38+
->setDistance(10);
3939
$shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
4040

4141
// Create a shape (text)
42-
echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
42+
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
4343
$shape = $currentSlide->createRichTextShape()
44-
->setHeight(300)
45-
->setWidth(600)
46-
->setOffsetX(170)
47-
->setOffsetY(180);
48-
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
44+
->setHeight(300)
45+
->setWidth(600)
46+
->setOffsetX(170)
47+
->setOffsetY(180);
48+
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
4949
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
5050
$textRun->getFont()->setBold(true)
51-
->setSize(60)
52-
->setColor( new Color( 'FFE06B20' ) );
51+
->setSize(60)
52+
->setColor(new Color('FFE06B20'));
5353

5454
// Save file
5555
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
5656
if (!CLI) {
57-
include_once 'Sample_Footer.php';
57+
include_once 'Sample_Footer.php';
5858
}

samples/Sample_03_Image.php

Lines changed: 25 additions & 14 deletions
Large diffs are not rendered by default.

samples/Sample_Header.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
$pageTitle .= 'PHPPresentation';
4444
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
4545

46-
$oShapeDrawing = new Drawing();
46+
$oShapeDrawing = new Drawing\File();
4747
$oShapeDrawing->setName('PHPPresentation logo')
4848
->setDescription('PHPPresentation logo')
4949
->setPath('./resources/phppowerpoint_logo.gif')
@@ -241,14 +241,18 @@ protected function displayPhpPresentation(PhpPresentation $oPHPPpt)
241241

242242
protected function displayShape(AbstractShape $shape)
243243
{
244-
if($shape instanceof MemoryDrawing) {
245-
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "MemoryDrawing"</span></li>');
246-
} elseif($shape instanceof Drawing) {
247-
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing"</span></li>');
244+
if($shape instanceof Drawing\Gd) {
245+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Gd"</span></li>');
246+
} elseif($shape instanceof Drawing\File) {
247+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\File"</span></li>');
248+
} elseif($shape instanceof Drawing\Base64) {
249+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Base64"</span></li>');
250+
} elseif($shape instanceof Drawing\Zip) {
251+
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Zip"</span></li>');
248252
} elseif($shape instanceof RichText) {
249253
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "RichText"</span></li>');
250254
} else {
251-
var_export($shape);
255+
var_dump($shape);
252256
}
253257
}
254258

samples/resources/SamplePassword.pptx

36.5 KB
Binary file not shown.
-4.17 MB
Binary file not shown.
6.96 MB
Binary file not shown.

0 commit comments

Comments
 (0)