1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheet\Worksheet; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; |
6
|
|
|
|
7
|
|
|
class Drawing extends BaseDrawing |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Path. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
private $path; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Create a new Drawing. |
18
|
|
|
*/ |
19
|
14 |
|
public function __construct() |
20
|
|
|
{ |
21
|
|
|
// Initialise values |
22
|
14 |
|
$this->path = ''; |
23
|
|
|
|
24
|
|
|
// Initialize parent |
25
|
14 |
|
parent::__construct(); |
26
|
14 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get Filename. |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
6 |
|
public function getFilename() |
34
|
|
|
{ |
35
|
6 |
|
return basename($this->path); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get indexed filename (using image index). |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
7 |
|
public function getIndexedFilename() |
44
|
|
|
{ |
45
|
7 |
|
$fileName = $this->getFilename(); |
46
|
7 |
|
$fileName = str_replace(' ', '_', $fileName); |
47
|
|
|
|
48
|
7 |
|
return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get Extension. |
53
|
|
|
* |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
6 |
|
public function getExtension() |
57
|
|
|
{ |
58
|
6 |
|
$exploded = explode('.', basename($this->path)); |
59
|
|
|
|
60
|
6 |
|
return $exploded[count($exploded) - 1]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get Path. |
65
|
|
|
* |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
12 |
|
public function getPath() |
69
|
|
|
{ |
70
|
12 |
|
return $this->path; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Set Path. |
75
|
|
|
* |
76
|
|
|
* @param string $pValue File path |
77
|
|
|
* @param bool $pVerifyFile Verify file |
78
|
|
|
* |
79
|
|
|
* @throws PhpSpreadsheetException |
80
|
|
|
* |
81
|
|
|
* @return Drawing |
82
|
|
|
*/ |
83
|
14 |
|
public function setPath($pValue, $pVerifyFile = true) |
84
|
|
|
{ |
85
|
14 |
|
if ($pVerifyFile) { |
86
|
12 |
|
if (file_exists($pValue)) { |
87
|
12 |
|
$this->path = $pValue; |
88
|
|
|
|
89
|
12 |
|
if ($this->width == 0 && $this->height == 0) { |
90
|
|
|
// Get width/height |
91
|
12 |
|
list($this->width, $this->height) = getimagesize($pValue); |
92
|
|
|
} |
93
|
|
|
} else { |
94
|
12 |
|
throw new PhpSpreadsheetException("File $pValue not found!"); |
95
|
|
|
} |
96
|
|
|
} else { |
97
|
4 |
|
$this->path = $pValue; |
98
|
|
|
} |
99
|
|
|
|
100
|
14 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get hash code. |
105
|
|
|
* |
106
|
|
|
* @return string Hash code |
107
|
|
|
*/ |
108
|
6 |
|
public function getHashCode() |
109
|
|
|
{ |
110
|
6 |
|
return md5( |
111
|
6 |
|
$this->path . |
112
|
6 |
|
parent::getHashCode() . |
113
|
6 |
|
__CLASS__ |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|