Ejemplo n.º 1
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';
}
Ejemplo n.º 2
0
define('IS_INDEX', SCRIPT_FILENAME == 'index');
require_once __DIR__ . '/../src/PhpPresentation/Autoloader.php';
Autoloader::register();
require_once __DIR__ . '/../vendor/autoload.php';
// Set writers
$writers = array('PowerPoint2007' => 'pptx', 'ODPresentation' => 'odp');
// Return to the caller script when runs by CLI
if (CLI) {
    return;
}
// Set titles and names
$pageHeading = str_replace('_', ' ', SCRIPT_FILENAME);
$pageTitle = IS_INDEX ? 'Welcome to ' : "{$pageHeading} - ";
$pageTitle .= 'PHPPresentation';
$pageHeading = IS_INDEX ? '' : "<h1>{$pageHeading}</h1>";
$oShapeDrawing = new Drawing();
$oShapeDrawing->setName('PHPPresentation logo')->setDescription('PHPPresentation logo')->setPath('./resources/phppowerpoint_logo.gif')->setHeight(36)->setOffsetX(10)->setOffsetY(10);
$oShapeDrawing->getShadow()->setVisible(true)->setDirection(45)->setDistance(10);
$oShapeDrawing->getHyperlink()->setUrl('https://github.com/PHPOffice/PHPPresentation/')->setTooltip('PHPPresentation');
// Create a shape (text)
$oShapeRichText = new RichText();
$oShapeRichText->setHeight(300)->setWidth(600)->setOffsetX(170)->setOffsetY(180);
$oShapeRichText->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $oShapeRichText->createTextRun('Thank you for using PHPPresentation!');
$textRun->getFont()->setBold(true)->setSize(60)->setColor(new Color('FFE06B20'));
// Populate samples
$files = '';
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if (preg_match('/^Sample_\\d+_/', $file)) {
            $name = str_replace('_', ' ', preg_replace('/(Sample_|\\.php)/', '', $file));
Ejemplo n.º 3
0
 public function testSetWidthAndHeight()
 {
     $object = new Drawing();
     $valueWidth = rand(1, 100);
     $valueHeight = $valueWidth / 2;
     $object->setResizeProportional(false);
     $object->setWidth($valueWidth);
     $object->setHeight($valueHeight);
     $object->setResizeProportional(true);
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing', $object->setWidthAndHeight($valueHeight, $valueWidth));
     $this->assertEquals($valueHeight, $object->getWidth());
     $this->assertEquals(ceil($valueHeight * ($valueHeight / $valueWidth)), $object->getHeight());
     $object = new Drawing();
     $valueWidth = rand(1, 100);
     $valueHeight = $valueWidth / 2;
     $object->setResizeProportional(false);
     $object->setWidth($valueWidth);
     $object->setHeight($valueHeight);
     $object->setResizeProportional(true);
     $this->assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing', $object->setWidthAndHeight($valueWidth, $valueHeight));
     $this->assertEquals($valueHeight, $object->getHeight());
     $this->assertEquals(ceil($valueWidth * ($valueHeight / $valueHeight)), $object->getWidth());
 }