Completed
Pull Request — develop (#209)
by Franck
07:03
created

ThumbnailsThumbnail   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 37
ccs 0
cts 25
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 31 3
1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
4
5
class ThumbnailsThumbnail extends AbstractDecoratorWriter
6
{
7
    /**
8
     * @return ZipInterface
9
     */
10
    public function render()
11
    {
12
        $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
13
        if ($pathThumbnail) {
14
            // Size : 128x128 pixel
15
            // PNG : 8bit, non-interlaced with full alpha transparency
16
            $gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
17
            if ($gdImage) {
18
                list($width, $height) = getimagesize($pathThumbnail);
19
20
                $gdRender = imagecreatetruecolor(128, 128);
21
                $colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
22
                imagecolortransparent($gdRender, $colorBgAlpha);
23
                imagefill($gdRender, 0, 0, $colorBgAlpha);
24
                imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
25
                imagetruecolortopalette($gdRender, false, 255);
26
                imagesavealpha($gdRender, true);
27
28
                ob_start();
29
                imagepng($gdRender);
30
                $imageContents = ob_get_contents();
31
                ob_end_clean();
32
33
                imagedestroy($gdRender);
34
                imagedestroy($gdImage);
35
36
                $this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents);
37
            }
38
        }
39
        return $this->getZip();
40
    }
41
}
42