Drawing.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  26. */
  27. /**
  28. * PHPExcel_Worksheet_Drawing
  29. *
  30. * @category PHPExcel
  31. * @package PHPExcel_Worksheet_Drawing
  32. * @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  33. */
  34. class PHPExcel_Worksheet_Drawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  35. {
  36. /**
  37. * Path
  38. *
  39. * @var string
  40. */
  41. private $_path;
  42. /**
  43. * Create a new PHPExcel_Worksheet_Drawing
  44. */
  45. public function __construct()
  46. {
  47. // Initialise values
  48. $this->_path = '';
  49. // Initialize parent
  50. parent::__construct();
  51. }
  52. /**
  53. * Get Filename
  54. *
  55. * @return string
  56. */
  57. public function getFilename() {
  58. return basename($this->_path);
  59. }
  60. /**
  61. * Get indexed filename (using image index)
  62. *
  63. * @return string
  64. */
  65. public function getIndexedFilename() {
  66. $fileName = $this->getFilename();
  67. $fileName = str_replace(' ', '_', $fileName);
  68. return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension();
  69. }
  70. /**
  71. * Get Extension
  72. *
  73. * @return string
  74. */
  75. public function getExtension() {
  76. $exploded = explode(".", basename($this->_path));
  77. return $exploded[count($exploded) - 1];
  78. }
  79. /**
  80. * Get Path
  81. *
  82. * @return string
  83. */
  84. public function getPath() {
  85. return $this->_path;
  86. }
  87. /**
  88. * Set Path
  89. *
  90. * @param string $pValue File path
  91. * @param boolean $pVerifyFile Verify file
  92. * @throws PHPExcel_Exception
  93. * @return PHPExcel_Worksheet_Drawing
  94. */
  95. public function setPath($pValue = '', $pVerifyFile = true) {
  96. if ($pVerifyFile) {
  97. if (file_exists($pValue)) {
  98. $this->_path = $pValue;
  99. if ($this->_width == 0 && $this->_height == 0) {
  100. // Get width/height
  101. list($this->_width, $this->_height) = getimagesize($pValue);
  102. }
  103. } else {
  104. throw new PHPExcel_Exception("File $pValue not found!");
  105. }
  106. } else {
  107. $this->_path = $pValue;
  108. }
  109. return $this;
  110. }
  111. /**
  112. * Get hash code
  113. *
  114. * @return string Hash code
  115. */
  116. public function getHashCode() {
  117. return md5(
  118. $this->_path
  119. . parent::getHashCode()
  120. . __CLASS__
  121. );
  122. }
  123. /**
  124. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  125. */
  126. public function __clone() {
  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. }