Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
Image | |
100.00% |
12 / 12 |
|
100.00% |
5 / 5 |
10 | |
100.00% |
1 / 1 |
getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPath | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |||
getFilename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
getExtension | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getIndexedFilename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
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 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation\Slide\Background; |
21 | |
22 | use PhpOffice\PhpPresentation\Exception\FileNotFoundException; |
23 | use PhpOffice\PhpPresentation\Slide\AbstractBackground; |
24 | |
25 | class Image extends AbstractBackground |
26 | { |
27 | /** |
28 | * @var string |
29 | */ |
30 | public $relationId; |
31 | |
32 | /** |
33 | * Path. |
34 | * |
35 | * @var string |
36 | */ |
37 | protected $path; |
38 | |
39 | /** |
40 | * @var int |
41 | */ |
42 | protected $height; |
43 | |
44 | /** |
45 | * @var int |
46 | */ |
47 | protected $width; |
48 | |
49 | /** |
50 | * Get Path. |
51 | */ |
52 | public function getPath(): ?string |
53 | { |
54 | return $this->path; |
55 | } |
56 | |
57 | /** |
58 | * Set Path. |
59 | * |
60 | * @param string $pValue File path |
61 | * @param bool $pVerifyFile Verify file |
62 | * |
63 | * @return self |
64 | */ |
65 | public function setPath(string $pValue = '', bool $pVerifyFile = true) |
66 | { |
67 | if ($pVerifyFile) { |
68 | if (!file_exists($pValue)) { |
69 | throw new FileNotFoundException($pValue); |
70 | } |
71 | |
72 | if (0 == $this->width && 0 == $this->height) { |
73 | // Get width/height |
74 | [$this->width, $this->height] = getimagesize($pValue); |
75 | } |
76 | } |
77 | $this->path = $pValue; |
78 | |
79 | return $this; |
80 | } |
81 | |
82 | /** |
83 | * Get Filename. |
84 | */ |
85 | public function getFilename(): string |
86 | { |
87 | return $this->path ? basename($this->path) : ''; |
88 | } |
89 | |
90 | /** |
91 | * Get Extension. |
92 | */ |
93 | public function getExtension(): string |
94 | { |
95 | $exploded = explode('.', $this->getFilename()); |
96 | |
97 | return $exploded[count($exploded) - 1]; |
98 | } |
99 | |
100 | /** |
101 | * Get indexed filename (using image index). |
102 | * |
103 | * @param string $numSlide |
104 | * |
105 | * @return string |
106 | */ |
107 | public function getIndexedFilename($numSlide) |
108 | { |
109 | return 'background_' . $numSlide . '.' . $this->getExtension(); |
110 | } |
111 | } |