Drawing.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. class PHPExcel_Worksheet_Drawing extends PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
  8. {
  9. /**
  10. * Path
  11. *
  12. * @var string
  13. */
  14. private $path;
  15. /**
  16. * Create a new PHPExcel_Worksheet_Drawing
  17. */
  18. public function __construct()
  19. {
  20. // Initialise values
  21. $this->path = '';
  22. // Initialize parent
  23. parent::__construct();
  24. }
  25. /**
  26. * Get Filename
  27. *
  28. * @return string
  29. */
  30. public function getFilename()
  31. {
  32. return basename($this->path);
  33. }
  34. /**
  35. * Get indexed filename (using image index)
  36. *
  37. * @return string
  38. */
  39. public function getIndexedFilename()
  40. {
  41. $fileName = $this->getFilename();
  42. $fileName = str_replace(' ', '_', $fileName);
  43. return str_replace('.' . $this->getExtension(), '', $fileName) . $this->getImageIndex() . '.' . $this->getExtension();
  44. }
  45. /**
  46. * Get Extension
  47. *
  48. * @return string
  49. */
  50. public function getExtension()
  51. {
  52. $exploded = explode(".", basename($this->path));
  53. return $exploded[count($exploded) - 1];
  54. }
  55. /**
  56. * Get Path
  57. *
  58. * @return string
  59. */
  60. public function getPath()
  61. {
  62. return $this->path;
  63. }
  64. /**
  65. * Set Path
  66. *
  67. * @param string $pValue File path
  68. * @param boolean $pVerifyFile Verify file
  69. * @throws PHPExcel_Exception
  70. * @return PHPExcel_Worksheet_Drawing
  71. */
  72. public function setPath($pValue = '', $pVerifyFile = true)
  73. {
  74. if ($pVerifyFile) {
  75. if (file_exists($pValue)) {
  76. $this->path = $pValue;
  77. if ($this->width == 0 && $this->height == 0) {
  78. // Get width/height
  79. list($this->width, $this->height) = getimagesize($pValue);
  80. }
  81. } else {
  82. throw new PHPExcel_Exception("File $pValue not found!");
  83. }
  84. } else {
  85. $this->path = $pValue;
  86. }
  87. return $this;
  88. }
  89. /**
  90. * Get hash code
  91. *
  92. * @return string Hash code
  93. */
  94. public function getHashCode()
  95. {
  96. return md5(
  97. $this->path .
  98. parent::getHashCode() .
  99. __CLASS__
  100. );
  101. }
  102. /**
  103. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  104. */
  105. public function __clone()
  106. {
  107. $vars = get_object_vars($this);
  108. foreach ($vars as $key => $value) {
  109. if (is_object($value)) {
  110. $this->$key = clone $value;
  111. } else {
  112. $this->$key = $value;
  113. }
  114. }
  115. }
  116. }