Skip to content

Commit f8e6e7c

Browse files
committed
#192 : Image Adapter (Media Bugfix)
1 parent f33d8f3 commit f8e6e7c

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

src/PhpPresentation/PresentationProperties.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class PresentationProperties
6464
protected $zoom = 1;
6565

6666
/*
67-
* @var boolean
67+
* @var string
6868
*/
6969
protected $lastView = self::VIEW_SLIDE;
7070

@@ -104,7 +104,7 @@ public function getThumbnailPath()
104104

105105
/**
106106
* Define the path for the thumbnail file / preview picture
107-
* @param string $value
107+
* @param string $path
108108
* @return \PhpOffice\PhpPresentation\PresentationProperties
109109
*/
110110
public function setThumbnailPath($path = '')

src/PhpPresentation/Shape/Drawing/Base64.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ public function getIndexedFilename()
8888
*/
8989
public function getMimeType()
9090
{
91-
list(, $sImage) = explode(';', $this->getData());
92-
list(, $sImage) = explode(',', $sImage);
91+
$sImage = $this->getContents();
9392
if (!function_exists('getimagesizefromstring')) {
9493
$uri = 'data://application/octet-stream;base64,' . base64_encode($sImage);
9594
$image = getimagesize($uri);
9695
} else {
9796
$image = getimagesizefromstring($sImage);
9897
}
99-
image_type_to_mime_type($image[2]);
98+
return image_type_to_mime_type($image[2]);
10099
}
101100
}

src/PhpPresentation/Shape/Drawing/File.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
class File extends AbstractDrawingAdapter
88
{
99
/**
10-
* @var SplFileInfo
10+
* @var string
1111
*/
12-
protected $oFileInfo;
12+
protected $path;
1313

1414
/**
1515
* Get Path
@@ -18,7 +18,7 @@ class File extends AbstractDrawingAdapter
1818
*/
1919
public function getPath()
2020
{
21-
return $this->oFileInfo->getPathname();
21+
return $this->path;
2222
}
2323

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

4141
if ($this->width == 0 && $this->height == 0) {
4242
list($this->width, $this->height) = getimagesize($this->getPath());
@@ -59,7 +59,7 @@ public function getContents()
5959
*/
6060
public function getExtension()
6161
{
62-
return $this->oFileInfo->getExtension();
62+
return pathinfo($this->getPath(), PATHINFO_EXTENSION);
6363
}
6464

6565
/**
@@ -76,9 +76,9 @@ public function getMimeType()
7676
*/
7777
public function getIndexedFilename()
7878
{
79-
$output = str_replace('.' . $this->getExtension(), '', $this->oFileInfo->getFilename());
79+
$output = str_replace('.' . $this->getExtension(), '', pathinfo($this->getPath(), PATHINFO_FILENAME));
8080
$output .= $this->getImageIndex();
81-
$output .= $this->getExtension();
81+
$output .= '.'.$this->getExtension();
8282
$output = str_replace(' ', '_', $output);
8383
return $output;
8484
}

src/PhpPresentation/Shape/Drawing/ZipFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getIndexedFilename()
9090
$output = substr($this->getPath(), strpos($this->getPath(), '#') + 1);
9191
$output = str_replace('.' . $this->getExtension(), '', $output);
9292
$output .= $this->getImageIndex();
93-
$output .= $this->getExtension();
93+
$output .= '.'.$this->getExtension();
9494
$output = str_replace(' ', '_', $output);
9595
return $output;
9696
}

src/PhpPresentation/Shape/Media.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,29 @@
1818
namespace PhpOffice\PhpPresentation\Shape;
1919

2020
use PhpOffice\PhpPresentation\ComparableInterface;
21+
use PhpOffice\PhpPresentation\Shape\Drawing\File;
2122

2223
/**
2324
* Media element
2425
*/
25-
class Media extends Drawing implements ComparableInterface
26+
class Media extends File implements ComparableInterface
2627
{
28+
29+
/**
30+
* @return string
31+
*/
32+
public function getMimeType()
33+
{
34+
switch (strtolower($this->getExtension())) {
35+
case 'mp4':
36+
$mimetype = 'video/mp4';
37+
break;
38+
case 'ogv':
39+
$mimetype = 'video/ogg';
40+
break;
41+
default:
42+
$mimetype = 'application/octet-stream';
43+
}
44+
return $mimetype;
45+
}
2746
}

src/PhpPresentation/Slide/Background/Image.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,13 @@ public function setPath($pValue = '', $pVerifyFile = true)
5252
if (!file_exists($pValue)) {
5353
throw new \Exception("File $pValue not found!");
5454
}
55-
$this->path = $pValue;
5655

5756
if ($this->width == 0 && $this->height == 0) {
5857
// Get width/height
5958
list($this->width, $this->height) = getimagesize($pValue);
6059
}
61-
62-
} else {
63-
$this->path = $pValue;
6460
}
65-
61+
$this->path = $pValue;
6662
return $this;
6763
}
6864

src/PhpPresentation/Writer/ODPresentation/Content.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public function writeShapeMedia(XMLWriter $objWriter, Media $shape)
336336
$objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
337337
// draw:frame > draw:plugin
338338
$objWriter->startElement('draw:plugin');
339-
$objWriter->writeAttribute('xlink:href', 'Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension());
339+
$objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename());
340340
$objWriter->writeAttribute('xlink:type', 'simple');
341341
$objWriter->writeAttribute('xlink:show', 'embed');
342342
$objWriter->writeAttribute('xlink:actuate', 'onLoad');

src/PhpPresentation/Writer/PowerPoint2007/PptMedia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function render()
1313
{
1414
for ($i = 0; $i < $this->getDrawingHashTable()->count(); ++$i) {
1515
$shape = $this->getDrawingHashTable()->getByIndex($i);
16-
if (!$shape instanceof Drawing\AbstractDrawingAdapter && !$shape instanceof Media) {
16+
if (!$shape instanceof Drawing\AbstractDrawingAdapter) {
1717
continue;
1818
}
1919
$this->getZip()->addFromString('ppt/media/' . $shape->getIndexedFilename(), $shape->getContents());

0 commit comments

Comments
 (0)