Image.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * PHPWord
  4. *
  5. * Copyright (c) 2011 PHPWord
  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 PHPWord
  22. * @package PHPWord
  23. * @copyright Copyright (c) 010 PHPWord
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version Beta 0.6.3, 08.07.2011
  26. */
  27. /**
  28. * PHPWord_Section_Image
  29. *
  30. * @category PHPWord
  31. * @package PHPWord_Section
  32. * @copyright Copyright (c) 2011 PHPWord
  33. */
  34. class PHPWord_Section_Image {
  35. /**
  36. * Image Src
  37. *
  38. * @var string
  39. */
  40. private $_src;
  41. /**
  42. * Image Style
  43. *
  44. * @var PHPWord_Style_Image
  45. */
  46. private $_style;
  47. /**
  48. * Image Relation ID
  49. *
  50. * @var string
  51. */
  52. private $_rId;
  53. /**
  54. * Is Watermark
  55. *
  56. * @var bool
  57. */
  58. private $_isWatermark;
  59. /**
  60. * Create a new Image
  61. *
  62. * @param string $src
  63. * @param mixed style
  64. */
  65. public function __construct($src, $style = null, $isWatermark = false) {
  66. $_supportedImageTypes = array('jpg', 'jpeg', 'gif', 'png', 'bmp', 'tif', 'tiff');
  67. $inf = pathinfo($src);
  68. $ext = strtolower($inf['extension']);
  69. if(file_exists($src) && in_array($ext, $_supportedImageTypes)) {
  70. $this->_src = $src;
  71. $this->_isWatermark = $isWatermark;
  72. $this->_style = new PHPWord_Style_Image();
  73. if(!is_null($style) && is_array($style)) {
  74. foreach($style as $key => $value) {
  75. if(substr($key, 0, 1) != '_') {
  76. $key = '_'.$key;
  77. }
  78. $this->_style->setStyleValue($key, $value);
  79. }
  80. }
  81. if($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
  82. $imgData = getimagesize($this->_src);
  83. $this->_style->setWidth($imgData[0]);
  84. $this->_style->setHeight($imgData[1]);
  85. }
  86. return $this;
  87. } else {
  88. return false;
  89. }
  90. }
  91. /**
  92. * Get Image style
  93. *
  94. * @return PHPWord_Style_Image
  95. */
  96. public function getStyle() {
  97. return $this->_style;
  98. }
  99. /**
  100. * Get Image Relation ID
  101. *
  102. * @return int
  103. */
  104. public function getRelationId() {
  105. return $this->_rId;
  106. }
  107. /**
  108. * Set Image Relation ID
  109. *
  110. * @param int $rId
  111. */
  112. public function setRelationId($rId) {
  113. $this->_rId = $rId;
  114. }
  115. /**
  116. * Get Image Source
  117. *
  118. * @return string
  119. */
  120. public function getSource() {
  121. return $this->_src;
  122. }
  123. /**
  124. * Get Image Media ID
  125. *
  126. * @return string
  127. */
  128. public function getMediaId() {
  129. return md5($this->_src);
  130. }
  131. /**
  132. * Get IsWatermark
  133. *
  134. * @return int
  135. */
  136. public function getIsWatermark() {
  137. return $this->_isWatermark;
  138. }
  139. /**
  140. * Set IsWatermark
  141. *
  142. * @param bool $pValue
  143. */
  144. public function setIsWatermark($pValue) {
  145. $this->_isWatermark = $pValue;
  146. }
  147. }
  148. ?>