Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ThumbnailsThumbnail
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2/**
3 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4 * presentations documents.
5 *
6 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7 * General Public License version 3 as published by the Free Software Foundation.
8 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12 *
13 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
21
22use PhpOffice\Common\Adapter\Zip\ZipInterface;
23
24class ThumbnailsThumbnail extends AbstractDecoratorWriter
25{
26    public function render(): ZipInterface
27    {
28        $pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
29        if ($pathThumbnail) {
30            // Size : 128x128 pixel
31            // PNG : 8bit, non-interlaced with full alpha transparency
32            $gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
33            if ($gdImage) {
34                [$width, $height] = getimagesize($pathThumbnail);
35
36                $gdRender = imagecreatetruecolor(128, 128);
37                $colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
38                imagecolortransparent($gdRender, $colorBgAlpha);
39                imagefill($gdRender, 0, 0, $colorBgAlpha);
40                imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
41                imagetruecolortopalette($gdRender, false, 255);
42                imagesavealpha($gdRender, true);
43
44                ob_start();
45                imagepng($gdRender);
46                $imageContents = ob_get_contents();
47                ob_end_clean();
48
49                imagedestroy($gdRender);
50                imagedestroy($gdImage);
51
52                $this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents);
53            }
54        }
55
56        return $this->getZip();
57    }
58}