Skip to content

Commit

Permalink
PHPOffice#192 : Image Adapter (Media Bugfix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Apr 1, 2016
1 parent f33d8f3 commit f8e6e7c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
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
5 changes: 2 additions & 3 deletions src/PhpPresentation/Shape/Drawing/Base64.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ public function getIndexedFilename()
*/
public function getMimeType()
{
list(, $sImage) = explode(';', $this->getData());
list(, $sImage) = explode(',', $sImage);
$sImage = $this->getContents();
if (!function_exists('getimagesizefromstring')) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($sImage);
$image = getimagesize($uri);
} else {
$image = getimagesizefromstring($sImage);
}
image_type_to_mime_type($image[2]);
return image_type_to_mime_type($image[2]);
}
}
14 changes: 7 additions & 7 deletions src/PhpPresentation/Shape/Drawing/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class File extends AbstractDrawingAdapter
{
/**
* @var SplFileInfo
* @var string
*/
protected $oFileInfo;
protected $path;

/**
* Get Path
Expand All @@ -18,7 +18,7 @@ class File extends AbstractDrawingAdapter
*/
public function getPath()
{
return $this->oFileInfo->getPathname();
return $this->path;
}

/**
Expand All @@ -36,7 +36,7 @@ public function setPath($pValue = '', $pVerifyFile = true)
throw new \Exception("File $pValue not found!");
}
}
$this->oFileInfo = new SplFileInfo($pValue);
$this->path = $pValue;

if ($this->width == 0 && $this->height == 0) {
list($this->width, $this->height) = getimagesize($this->getPath());
Expand All @@ -59,7 +59,7 @@ public function getContents()
*/
public function getExtension()
{
return $this->oFileInfo->getExtension();
return pathinfo($this->getPath(), PATHINFO_EXTENSION);
}

/**
Expand All @@ -76,9 +76,9 @@ public function getMimeType()
*/
public function getIndexedFilename()
{
$output = str_replace('.' . $this->getExtension(), '', $this->oFileInfo->getFilename());
$output = str_replace('.' . $this->getExtension(), '', pathinfo($this->getPath(), PATHINFO_FILENAME));
$output .= $this->getImageIndex();
$output .= $this->getExtension();
$output .= '.'.$this->getExtension();
$output = str_replace(' ', '_', $output);
return $output;
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPresentation/Shape/Drawing/ZipFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function getIndexedFilename()
$output = substr($this->getPath(), strpos($this->getPath(), '#') + 1);
$output = str_replace('.' . $this->getExtension(), '', $output);
$output .= $this->getImageIndex();
$output .= $this->getExtension();
$output .= '.'.$this->getExtension();
$output = str_replace(' ', '_', $output);
return $output;
}
Expand Down
21 changes: 20 additions & 1 deletion src/PhpPresentation/Shape/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,29 @@
namespace PhpOffice\PhpPresentation\Shape;

use PhpOffice\PhpPresentation\ComparableInterface;
use PhpOffice\PhpPresentation\Shape\Drawing\File;

/**
* Media element
*/
class Media extends Drawing implements ComparableInterface
class Media extends File implements ComparableInterface
{

/**
* @return string
*/
public function getMimeType()
{
switch (strtolower($this->getExtension())) {
case 'mp4':
$mimetype = 'video/mp4';
break;
case 'ogv':
$mimetype = 'video/ogg';
break;
default:
$mimetype = 'application/octet-stream';
}
return $mimetype;
}
}
6 changes: 1 addition & 5 deletions src/PhpPresentation/Slide/Background/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ public function setPath($pValue = '', $pVerifyFile = true)
if (!file_exists($pValue)) {
throw new \Exception("File $pValue not found!");
}
$this->path = $pValue;

if ($this->width == 0 && $this->height == 0) {
// Get width/height
list($this->width, $this->height) = getimagesize($pValue);
}

} else {
$this->path = $pValue;
}

$this->path = $pValue;
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpPresentation/Writer/ODPresentation/Content.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function writeShapeMedia(XMLWriter $objWriter, Media $shape)
$objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
// draw:frame > draw:plugin
$objWriter->startElement('draw:plugin');
$objWriter->writeAttribute('xlink:href', 'Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension());
$objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename());
$objWriter->writeAttribute('xlink:type', 'simple');
$objWriter->writeAttribute('xlink:show', 'embed');
$objWriter->writeAttribute('xlink:actuate', 'onLoad');
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPresentation/Writer/PowerPoint2007/PptMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function render()
{
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
$shape = $this->getDrawingHashTable()->getByIndex($i);
if (!$shape instanceof Drawing\AbstractDrawingAdapter && !$shape instanceof Media) {
if (!$shape instanceof Drawing\AbstractDrawingAdapter) {
continue;
}
$this->getZip()->addFromString('ppt/media/' . $shape->getIndexedFilename(), $shape->getContents());
Expand Down

0 comments on commit f8e6e7c

Please sign in to comment.