Completed
Pull Request — develop (#565)
by
unknown
06:14
created

DocPropsThumbnail::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.9862

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 4
cts 13
cp 0.3076
rs 9.584
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 5.9862
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\PowerPoint2007;
4
5
class DocPropsThumbnail extends AbstractDecoratorWriter
6
{
7
    /**
8
     * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
9
     * @throws \Exception
10
     */
11 5
    public function render()
12
    {
13 5
        $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
14
15 5
        if ($pathThumbnail) {
16
            $fileThumbnail = file_get_contents($pathThumbnail);
17
            $gdImage = imagecreatefromstring($fileThumbnail);
18
            if ($gdImage) {
19
                ob_start();
20
                imagejpeg($gdImage);
21
                $imageContents = ob_get_contents();
22
                ob_end_clean();
23
                imagedestroy($gdImage);
24
25
                $this->getZip()->addFromString('docProps/thumbnail.jpeg', $imageContents);
26
            }
27
        }
28
29
        // Return
30 5
        return $this->getZip();
31
    }
32
}
33