예제 #1
0
 public function testRenderingFunction()
 {
     $object = new MemoryDrawing();
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\MemoryDrawing', $object->setRenderingFunction());
     $this->assertEquals(MemoryDrawing::RENDERING_DEFAULT, $object->getRenderingFunction());
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\MemoryDrawing', $object->setRenderingFunction(MemoryDrawing::RENDERING_JPEG));
     $this->assertEquals(MemoryDrawing::RENDERING_JPEG, $object->getRenderingFunction());
 }
예제 #2
0
 public function testMemoryDrawing()
 {
     $oPhpPresentation = new PhpPresentation();
     $oSlide = $oPhpPresentation->getActiveSlide();
     $oShape = new MemoryDrawing();
     $gdImage = @imagecreatetruecolor(140, 20);
     $textColor = imagecolorallocate($gdImage, 255, 255, 255);
     imagestring($gdImage, 1, 5, 5, 'Created with PhpPresentation', $textColor);
     $oShape->setImageResource($gdImage)->setRenderingFunction(MemoryDrawing::RENDERING_JPEG)->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
     $oSlide->addShape($oShape);
     $pres = TestHelperDOCX::getDocument($oPhpPresentation, 'ODPresentation');
     $element = '/manifest:manifest/manifest:file-entry[5]';
     $this->assertTrue($pres->elementExists($element, 'META-INF/manifest.xml'));
     $this->assertEquals('Pictures/' . $oShape->getIndexedFilename(), $pres->getElementAttribute($element, 'manifest:full-path', 'META-INF/manifest.xml'));
 }
예제 #3
0
 /**
  *
  * @param XMLReader $document
  * @param \DOMElement $node
  * @param string $baseFile
  */
 protected function loadShapeDrawing(XMLReader $document, \DOMElement $node, $baseFile)
 {
     // Core
     $oShape = new MemoryDrawing();
     $oShape->getShadow()->setVisible(false);
     // Variables
     $fileRels = 'ppt/slides/_rels/' . $baseFile . '.rels';
     $oElement = $document->getElement('p:nvPicPr/p:cNvPr', $node);
     if ($oElement) {
         $oShape->setName($oElement->hasAttribute('name') ? $oElement->getAttribute('name') : '');
         $oShape->setDescription($oElement->hasAttribute('descr') ? $oElement->getAttribute('descr') : '');
     }
     $oElement = $document->getElement('p:blipFill/a:blip', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('r:embed') && isset($this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')])) {
             $pathImage = 'ppt/slides/' . $this->arrayRels[$fileRels][$oElement->getAttribute('r:embed')];
             $pathImage = explode('/', $pathImage);
             foreach ($pathImage as $key => $partPath) {
                 if ($partPath == '..') {
                     unset($pathImage[$key - 1]);
                     unset($pathImage[$key]);
                 }
             }
             $pathImage = implode('/', $pathImage);
             $imageFile = $this->oZip->getFromName($pathImage);
             if (!empty($imageFile)) {
                 $oShape->setImageResource(imagecreatefromstring($imageFile));
             }
         }
     }
     $oElement = $document->getElement('p:spPr/a:xfrm', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('rot')) {
             $oShape->setRotation(CommonDrawing::angleToDegrees($oElement->getAttribute('rot')));
         }
     }
     $oElement = $document->getElement('p:spPr/a:xfrm/a:off', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('x')) {
             $oShape->setOffsetX(CommonDrawing::emuToPixels($oElement->getAttribute('x')));
         }
         if ($oElement->hasAttribute('y')) {
             $oShape->setOffsetY(CommonDrawing::emuToPixels($oElement->getAttribute('y')));
         }
     }
     $oElement = $document->getElement('p:spPr/a:xfrm/a:ext', $node);
     if ($oElement) {
         if ($oElement->hasAttribute('cx')) {
             $oShape->setWidth(CommonDrawing::emuToPixels($oElement->getAttribute('cx')));
         }
         if ($oElement->hasAttribute('cy')) {
             $oShape->setHeight(CommonDrawing::emuToPixels($oElement->getAttribute('cy')));
         }
     }
     $oElement = $document->getElement('p:spPr/a:effectLst', $node);
     if ($oElement) {
         $oShape->getShadow()->setVisible(true);
         $oSubElement = $document->getElement('a:outerShdw', $oElement);
         if ($oSubElement) {
             if ($oSubElement->hasAttribute('blurRad')) {
                 $oShape->getShadow()->setBlurRadius(CommonDrawing::emuToPixels($oSubElement->getAttribute('blurRad')));
             }
             if ($oSubElement->hasAttribute('dist')) {
                 $oShape->getShadow()->setDistance(CommonDrawing::emuToPixels($oSubElement->getAttribute('dist')));
             }
             if ($oSubElement->hasAttribute('dir')) {
                 $oShape->getShadow()->setDirection(CommonDrawing::angleToDegrees($oSubElement->getAttribute('dir')));
             }
             if ($oSubElement->hasAttribute('algn')) {
                 $oShape->getShadow()->setAlignment($oSubElement->getAttribute('algn'));
             }
         }
         $oSubElement = $document->getElement('a:outerShdw/a:srgbClr', $oElement);
         if ($oSubElement) {
             if ($oSubElement->hasAttribute('val')) {
                 $oColor = new Color();
                 $oColor->setRGB($oSubElement->getAttribute('val'));
                 $oShape->getShadow()->setColor($oColor);
             }
         }
         $oSubElement = $document->getElement('a:outerShdw/a:srgbClr/a:alpha', $oElement);
         if ($oSubElement) {
             if ($oSubElement->hasAttribute('val')) {
                 $oShape->getShadow()->setAlpha((int) $oSubElement->getAttribute('val') / 1000);
             }
         }
     }
     $this->oPhpPresentation->getActiveSlide()->addShape($oShape);
 }
예제 #4
0
 /**
  *
  * @param \DOMElement $oNodeFrame
  */
 protected function loadShapeDrawing(\DOMElement $oNodeFrame)
 {
     // Core
     $oShape = new MemoryDrawing();
     $oShape->getShadow()->setVisible(false);
     $oNodeImage = $this->oXMLReader->getElement('draw:image', $oNodeFrame);
     if ($oNodeImage) {
         if ($oNodeImage->hasAttribute('xlink:href')) {
             $imageFile = $this->oZip->getFromName($oNodeImage->getAttribute('xlink:href'));
             if (!empty($imageFile)) {
                 $oShape->setImageResource(imagecreatefromstring($imageFile));
             }
         }
     }
     $oShape->setName($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : '');
     $oShape->setDescription($oNodeFrame->hasAttribute('draw:name') ? $oNodeFrame->getAttribute('draw:name') : '');
     $oShape->setResizeProportional(false);
     $oShape->setWidth($oNodeFrame->hasAttribute('svg:width') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:width'), 0, -2))) : '');
     $oShape->setHeight($oNodeFrame->hasAttribute('svg:height') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:height'), 0, -2))) : '');
     $oShape->setResizeProportional(true);
     $oShape->setOffsetX($oNodeFrame->hasAttribute('svg:x') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:x'), 0, -2))) : '');
     $oShape->setOffsetY($oNodeFrame->hasAttribute('svg:y') ? (int) round(CommonDrawing::centimetersToPixels(substr($oNodeFrame->getAttribute('svg:y'), 0, -2))) : '');
     if ($oNodeFrame->hasAttribute('draw:style-name')) {
         $keyStyle = $oNodeFrame->getAttribute('draw:style-name');
         if (isset($this->arrayStyles[$keyStyle])) {
             $oShape->setShadow($this->arrayStyles[$keyStyle]['shadow']);
         }
     }
     $this->oPhpPresentation->getActiveSlide()->addShape($oShape);
 }
예제 #5
0
<?php

include_once 'Sample_Header.php';
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\Shape\Drawing;
use PhpOffice\PhpPresentation\Shape\MemoryDrawing;
// Create new PHPPresentation object
echo date('H:i:s') . ' Create new PHPPresentation object' . EOL;
$objPHPPresentation = new PhpPresentation();
// Create slide
echo date('H:i:s') . ' Create slide' . EOL;
$currentSlide = $objPHPPresentation->getActiveSlide();
// Generate an image
echo date('H:i:s') . ' Generate an image' . EOL;
$gdImage = @imagecreatetruecolor(140, 20) or die('Cannot Initialize new GD image stream');
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
imagestring($gdImage, 1, 5, 5, 'Created with PHPPresentation', $textColor);
// Add a generated drawing to the slide
echo date('H:i:s') . ' Add a drawing to the slide' . EOL;
$shape = new MemoryDrawing();
$shape->setName('Sample image')->setDescription('Sample image')->setImageResource($gdImage)->setRenderingFunction(MemoryDrawing::RENDERING_JPEG)->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT)->setHeight(36)->setOffsetX(10)->setOffsetY(10);
$currentSlide->addShape($shape);
// Add a file drawing (GIF) to the slide
$shape = new Drawing();
$shape->setName('PHPPresentation logo')->setDescription('PHPPresentation logo')->setPath('./resources/phppowerpoint_logo.gif')->setHeight(36)->setOffsetX(10)->setOffsetY(100);
$currentSlide->addShape($shape);
// Save file
echo write($objPHPPresentation, basename(__FILE__, '.php'), $writers);
if (!CLI) {
    include_once 'Sample_Footer.php';
}