Skip to content

Commit

Permalink
Merge pull request #207 from Progi1984/issue192
Browse files Browse the repository at this point in the history
#192 : Image Adapter
  • Loading branch information
Progi1984 committed Apr 4, 2016
2 parents ee07eb7 + c53e5e6 commit 86946f7
Show file tree
Hide file tree
Showing 53 changed files with 1,055 additions and 930 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ PHPPresentation is a library written in pure PHP that provides a set of classes

shapes_chart
shapes_comment
shapes_drawing
shapes_media
shapes_richtext
shapes_table
Expand Down
13 changes: 0 additions & 13 deletions docs/shapes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,3 @@ Line
----

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


Drawing
-------

To create a drawing, use `createDrawingShape` method of slide.

.. code-block:: php
$drawing = $slide->createDrawingShape();
$drawing->setName('Unique name')
->setDescription('Description of the drawing')
->setPath('/path/to/drawing.filename');
75 changes: 75 additions & 0 deletions docs/shapes_drawing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.. _shapes_drawing:

Drawing
=======

To create a drawing, you have four sources : File, GD, Base64 and ZipFile.

File
----

To create a drawing, use `createDrawingShape` method of slide.

.. code-block:: php
$oShape = $oSlide->createDrawingShape();
$oShape->setName('Unique name')
->setDescription('Description of the drawing')
->setPath('/path/to/drawing.filename');
It's an alias for :

.. code-block:: php
use PhpOffice\PhpPresentation\Shape\Drawing\File;
$oShape = new File();
$oShape->setName('Unique name')
->setDescription('Description of the drawing')
->setPath('/path/to/drawing.filename');
$oSlide->addShape($oShape);
GD
--

.. code-block:: php
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
$gdImage = @imagecreatetruecolor($width, $height);
$oShape = new Gd();
$oShape->setName('Sample image')
->setDescription('Sample image')
->setImageResource($gdImage)
->setRenderingFunction(Drawing\Gd::RENDERING_JPEG)
->setMimeType(Drawing\Gd::MIMETYPE_DEFAULT);
$oSlide->addShape($oShape);
Base64
------

.. code-block:: php
use PhpOffice\PhpPresentation\Shape\Drawing\Base64;
$oShape = new Base64();
$oShape->setName('Sample image')
->setDescription('Sample image')
->setImageResource($gdImage)
->setData('data:image/jpeg;base64,..........');
$oSlide->addShape($oShape);
ZipFile
-------

.. code-block:: php
use PhpOffice\PhpPresentation\Shape\Drawing\ZipFile;
$oShape = new ZipFile();
$oShape->setName('Sample image')
->setDescription('Sample image')
->setPath('zip://myzipfile.zip#path/in/zip/img.ext')
$oSlide->addShape($oShape);
6 changes: 3 additions & 3 deletions docs/shapes_media.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Example:
use PhpOffice\PhpPresentation\Shape\Media;
$oMedia = new Media();
$oMedia->setPath('file.mp4');
$oMedia->setPath('file.wmv');
// $oMedia->setPath('file.ogv');
$oSlide->addShape($oMedia);
Expand All @@ -32,5 +32,5 @@ Example:
Quirks
------

For PowerPoint2007 Writer, the prefered file format is MP4.
For ODPresentation Writer, the prefered file format is OGV.
For Windows readers, the prefered file format is WMV.
For Linux readers, the prefered file format is OGV.
52 changes: 26 additions & 26 deletions samples/Sample_01_Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,48 @@
$objPHPPresentation = new PhpPresentation();

// Set properties
echo date('H:i:s') . ' Set properties'.EOL;
$objPHPPresentation->getProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 01 Title')
->setSubject('Sample 01 Subject')
->setDescription('Sample 01 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');
echo date('H:i:s') . ' Set properties' . EOL;
$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 01 Title')
->setSubject('Sample 01 Subject')
->setDescription('Sample 01 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');

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

// Create a shape (drawing)
echo date('H:i:s') . ' Create a shape (drawing)'.EOL;
echo date('H:i:s') . ' Create a shape (drawing)' . EOL;
$shape = $currentSlide->createDrawingShape();
$shape->setName('PHPPresentation logo')
->setDescription('PHPPresentation logo')
->setPath('./resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
->setDescription('PHPPresentation logo')
->setPath('./resources/phppowerpoint_logo.gif')
->setHeight(36)
->setOffsetX(10)
->setOffsetY(10);
$shape->getShadow()->setVisible(true)
->setDirection(45)
->setDistance(10);
->setDirection(45)
->setDistance(10);
$shape->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');

// Create a shape (text)
echo date('H:i:s') . ' Create a shape (rich text)'.EOL;
echo date('H:i:s') . ' Create a shape (rich text)' . EOL;
$shape = $currentSlide->createRichTextShape()
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal( Alignment::HORIZONTAL_CENTER );
->setHeight(300)
->setWidth(600)
->setOffsetX(170)
->setOffsetY(180);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)
->setSize(60)
->setColor( new Color( 'FFE06B20' ) );
->setSize(60)
->setColor(new Color('FFE06B20'));

// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
include_once 'Sample_Footer.php';
include_once 'Sample_Footer.php';
}
39 changes: 25 additions & 14 deletions samples/Sample_03_Image.php

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions samples/Sample_Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
$pageTitle .= 'PHPPresentation';
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";

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

protected function displayShape(AbstractShape $shape)
{
if($shape instanceof MemoryDrawing) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "MemoryDrawing"</span></li>');
} elseif($shape instanceof Drawing) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing"</span></li>');
if($shape instanceof Drawing\Gd) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Gd"</span></li>');
} elseif($shape instanceof Drawing\File) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\File"</span></li>');
} elseif($shape instanceof Drawing\Base64) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Base64"</span></li>');
} elseif($shape instanceof Drawing\Zip) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "Drawing\Zip"</span></li>');
} elseif($shape instanceof RichText) {
$this->append('<li><span class="shape" id="div'.$shape->getHashCode().'">Shape "RichText"</span></li>');
} else {
var_export($shape);
var_dump($shape);
}
}

Expand Down
Binary file added samples/resources/SamplePassword.pptx
Binary file not shown.
Binary file removed samples/resources/sintel_trailer-480p.mp4
Binary file not shown.
Binary file added samples/resources/sintel_trailer-480p.wmv
Binary file not shown.
2 changes: 1 addition & 1 deletion src/PhpPresentation/AbstractShape.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function setHyperlink(Hyperlink $pHyperlink = null)
*/
public function getHashCode()
{
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . $this->getFill()->getHashCode() . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
return md5((is_object($this->container)?$this->container->getHashCode():'') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . (is_null($this->getFill()) ? '' : $this->getFill()->getHashCode()) . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPresentation/PresentationProperties.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PresentationProperties
protected $zoom = 1;

/*
* @var boolean
* @var string
*/
protected $lastView = self::VIEW_SLIDE;

Expand Down Expand Up @@ -104,7 +104,7 @@ public function getThumbnailPath()

/**
* Define the path for the thumbnail file / preview picture
* @param string $value
* @param string $path
* @return \PhpOffice\PhpPresentation\PresentationProperties
*/
public function setThumbnailPath($path = '')
Expand Down
13 changes: 5 additions & 8 deletions src/PhpPresentation/Reader/ODPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
use PhpOffice\Common\XMLReader;
use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Hyperlink;
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
use PhpOffice\PhpPresentation\Shape\RichText;
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
use PhpOffice\PhpPresentation\Style\Bullet;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Font;
use PhpOffice\PhpPresentation\Style\Shadow;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\PhpOffice\PhpPresentation\Style;
use PhpOffice\PhpPresentation\Shape\RichText;
use PhpOffice\PhpPresentation\Shape\RichText\Paragraph;
use PhpOffice\Common\PhpOffice\Common;

/**
* Serialized format reader
Expand Down Expand Up @@ -365,9 +362,9 @@ protected function loadSlide(\DOMElement $nodeSlide)
protected function loadShapeDrawing(\DOMElement $oNodeFrame)
{
// Core
$oShape = new MemoryDrawing();
$oShape = new Gd();
$oShape->getShadow()->setVisible(false);

$oNodeImage = $this->oXMLReader->getElement('draw:image', $oNodeFrame);
if ($oNodeImage) {
if ($oNodeImage->hasAttribute('xlink:href')) {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

namespace PhpOffice\PhpPresentation\Reader;

use PhpOffice\PhpPresentation\Shape\Drawing\Gd;
use ZipArchive;
use PhpOffice\Common\XMLReader;
use PhpOffice\Common\Drawing as CommonDrawing;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
use PhpOffice\PhpPresentation\Style\Bullet;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\TemplateBased;
Expand Down Expand Up @@ -328,7 +328,7 @@ protected function loadSlide($sPart, $baseFile)
protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, $baseFile)
{
// Core
$oShape = new MemoryDrawing();
$oShape = new Gd();
$oShape->getShadow()->setVisible(false);
// Variables
$fileRels = 'ppt/slides/_rels/'.$baseFile.'.rels';
Expand Down
4 changes: 1 addition & 3 deletions src/PhpPresentation/Reader/PowerPoint97.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use PhpOffice\Common\Microsoft\OLERead;
use PhpOffice\PhpPresentation\Shape\Drawing;
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
use PhpOffice\PhpPresentation\Style\Alignment;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Shape\RichText;
Expand Down Expand Up @@ -887,7 +886,6 @@ private function readRecordDocumentContainer($stream, $pos)
$pos += $fontEmbedData4['recLen'];
$fontCollection['recLen'] -= $fontEmbedData4['recLen'];
}

} while ($fontCollection['recLen'] > 0);
}
}
Expand Down Expand Up @@ -1420,7 +1418,7 @@ private function readRecordOfficeArtSpContainer($stream, $pos)
$drawingPib = $shpPrimaryOptions['pib'];
if (isset($this->arrayPictures[$drawingPib - 1])) {
$gdImage = imagecreatefromstring($this->arrayPictures[$drawingPib - 1]);
$arrayReturn['shape'] = new MemoryDrawing();
$arrayReturn['shape'] = new Drawing\Gd();
$arrayReturn['shape']->setImageResource($gdImage);
}
} elseif (isset($shpPrimaryOptions['line']) && $shpPrimaryOptions['line']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Abstract drawing
*/
abstract class AbstractDrawing extends AbstractShape implements ComparableInterface
abstract class AbstractGraphic extends AbstractShape implements ComparableInterface
{
/**
* Image counter
Expand Down
5 changes: 3 additions & 2 deletions src/PhpPresentation/Shape/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace PhpOffice\PhpPresentation\Shape;

use PhpOffice\PhpPresentation\AbstractShape;
use PhpOffice\PhpPresentation\ComparableInterface;
use PhpOffice\PhpPresentation\Shape\Chart\Legend;
use PhpOffice\PhpPresentation\Shape\Chart\PlotArea;
Expand All @@ -26,7 +27,7 @@
/**
* Chart element
*/
class Chart extends AbstractDrawing implements ComparableInterface
class Chart extends AbstractGraphic implements ComparableInterface
{
/**
* Title
Expand Down Expand Up @@ -64,7 +65,7 @@ class Chart extends AbstractDrawing implements ComparableInterface
private $includeSpreadsheet = false;

/**
* Create a new \PhpOffice\PhpPresentation\Slide\MemoryDrawing
* Create a new Chart
*/
public function __construct()
{
Expand Down
Loading

0 comments on commit 86946f7

Please sign in to comment.