Skip to content

Commit

Permalink
PHPOffice#192 : Image Adapter (Feature)
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Mar 17, 2016
1 parent def4684 commit f20e1e9
Show file tree
Hide file tree
Showing 30 changed files with 654 additions and 357 deletions.
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';
}
27 changes: 19 additions & 8 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.
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
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
3 changes: 1 addition & 2 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 @@ -1422,7 +1421,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
40 changes: 1 addition & 39 deletions src/PhpPresentation/Shape/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Drawing element
*/
class Drawing extends AbstractDrawing implements ComparableInterface
class Drawing extends AbstractGraphic implements ComparableInterface
{
/**
* Path
Expand Down Expand Up @@ -75,44 +75,6 @@ public function getExtension()
return $exploded[count($exploded) - 1];
}

/**
* Get Path
*
* @return string
*/
public function getPath()
{
return $this->path;
}

/**
* Set Path
*
* @param string $pValue File path
* @param boolean $pVerifyFile Verify file
* @throws \Exception
* @return \PhpOffice\PhpPresentation\Shape\Drawing
*/
public function setPath($pValue = '', $pVerifyFile = true)
{
if ($pVerifyFile) {
if (file_exists($pValue)) {
$this->path = $pValue;

if ($this->width == 0 && $this->height == 0) {
// Get width/height
list($this->width, $this->height) = getimagesize($pValue);
}
} else {
throw new \Exception("File $pValue not found!");
}
} else {
$this->path = $pValue;
}

return $this;
}

/**
* Get hash code
*
Expand Down
28 changes: 28 additions & 0 deletions src/PhpPresentation/Shape/Drawing/AbstractDrawingAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace PhpOffice\PhpPresentation\Shape\Drawing;

use PhpOffice\PhpPresentation\Shape\AbstractGraphic;

abstract class AbstractDrawingAdapter extends AbstractGraphic
{
/**
* @return string
*/
abstract public function getContents();

/**
* @return string
*/
abstract public function getExtension();

/**
* @return string
*/
abstract public function getIndexedFilename();

/**
* @return string
*/
abstract public function getMimeType();
}
Loading

0 comments on commit f20e1e9

Please sign in to comment.