Drawing.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * PHPExcel_Worksheet_Drawing
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet_Drawing
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Worksheet_Drawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  28. {
  29. /**
  30. * Path
  31. *
  32. * @var string
  33. */
  34. private $path;
  35. /**
  36. * Create a new PHPExcel_Worksheet_Drawing
  37. */
  38. public function __construct()
  39. {
  40. // Initialise values
  41. $this->path = '';
  42. // Initialize parent
  43. parent::__construct();
  44. }
  45. /**
  46. * Get Filename
  47. *
  48. * @return string
  49. */
  50. public function getFilename()
  51. {
  52. return basename($this->path);
  53. }
  54. /**
  55. * Get indexed filename (using image index)
  56. *
  57. * @return string
  58. */
  59. public function getIndexedFilename()
  60. {
  61. $fileName = $this->getFilename();
  62. $fileName = str_replace(' ', '_', $fileName);
  63. return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension();
  64. }
  65. /**
  66. * Get Extension
  67. *
  68. * @return string
  69. */
  70. public function getExtension()
  71. {
  72. $exploded = explode(".", basename($this->path));
  73. return $exploded[count($exploded) - 1];
  74. }
  75. /**
  76. * Get Path
  77. *
  78. * @return string
  79. */
  80. public function getPath()
  81. {
  82. return $this->path;
  83. }
  84. /**
  85. * Set Path
  86. *
  87. * @param string $pValue File path
  88. * @param boolean $pVerifyFile Verify file
  89. * @throws PHPExcel_Exception
  90. * @return PHPExcel_Worksheet_Drawing
  91. */
  92. public function setPath($pValue = '', $pVerifyFile = true)
  93. {
  94. if ($pVerifyFile) {
  95. if (file_exists($pValue)) {
  96. $this->path = $pValue;
  97. if ($this->width == 0 && $this->height == 0) {
  98. // Get width/height
  99. list($this->width, $this->height) = getimagesize($pValue);
  100. }
  101. } else {
  102. throw new PHPExcel_Exception("File $pValue not found!");
  103. }
  104. } else {
  105. $this->path = $pValue;
  106. }
  107. return $this;
  108. }
  109. /**
  110. * Get hash code
  111. *
  112. * @return string Hash code
  113. */
  114. public function getHashCode()
  115. {
  116. return md5(
  117. $this->path .
  118. parent::getHashCode() .
  119. __CLASS__
  120. );
  121. }
  122. /**
  123. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  124. */
  125. public function __clone()
  126. {
  127. $vars = get_object_vars($this);
  128. foreach ($vars as $key => $value) {
  129. if (is_object($value)) {
  130. $this->$key = clone $value;
  131. } else {
  132. $this->$key = $value;
  133. }
  134. }
  135. }
  136. }