IImage.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Olivier Paroz <github@oparoz.com>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP;
  25. /**
  26. * Class for basic image manipulation
  27. * @since 8.1.0
  28. */
  29. interface IImage {
  30. /**
  31. * Determine whether the object contains an image resource.
  32. *
  33. * @return bool
  34. * @since 8.1.0
  35. */
  36. public function valid();
  37. /**
  38. * Returns the MIME type of the image or an empty string if no image is loaded.
  39. *
  40. * @return string
  41. * @since 8.1.0
  42. */
  43. public function mimeType();
  44. /**
  45. * Returns the width of the image or -1 if no image is loaded.
  46. *
  47. * @return int
  48. * @since 8.1.0
  49. */
  50. public function width();
  51. /**
  52. * Returns the height of the image or -1 if no image is loaded.
  53. *
  54. * @return int
  55. * @since 8.1.0
  56. */
  57. public function height();
  58. /**
  59. * Returns the width when the image orientation is top-left.
  60. *
  61. * @return int
  62. * @since 8.1.0
  63. */
  64. public function widthTopLeft();
  65. /**
  66. * Returns the height when the image orientation is top-left.
  67. *
  68. * @return int
  69. * @since 8.1.0
  70. */
  71. public function heightTopLeft();
  72. /**
  73. * Outputs the image.
  74. *
  75. * @param string $mimeType
  76. * @return bool
  77. * @since 8.1.0
  78. */
  79. public function show($mimeType = null);
  80. /**
  81. * Saves the image.
  82. *
  83. * @param string $filePath
  84. * @param string $mimeType
  85. * @return bool
  86. * @since 8.1.0
  87. */
  88. public function save($filePath = null, $mimeType = null);
  89. /**
  90. * @return resource Returns the image resource in any.
  91. * @since 8.1.0
  92. */
  93. public function resource();
  94. /**
  95. * @return string Returns the raw image data.
  96. * @since 8.1.0
  97. */
  98. public function data();
  99. /**
  100. * (I'm open for suggestions on better method name ;)
  101. * Get the orientation based on EXIF data.
  102. *
  103. * @return int The orientation or -1 if no EXIF data is available.
  104. * @since 8.1.0
  105. */
  106. public function getOrientation();
  107. /**
  108. * (I'm open for suggestions on better method name ;)
  109. * Fixes orientation based on EXIF data.
  110. *
  111. * @return bool
  112. * @since 8.1.0
  113. */
  114. public function fixOrientation();
  115. /**
  116. * Resizes the image preserving ratio.
  117. *
  118. * @param integer $maxSize The maximum size of either the width or height.
  119. * @return bool
  120. * @since 8.1.0
  121. */
  122. public function resize($maxSize);
  123. /**
  124. * @param int $width
  125. * @param int $height
  126. * @return bool
  127. * @since 8.1.0
  128. */
  129. public function preciseResize($width, $height);
  130. /**
  131. * Crops the image to the middle square. If the image is already square it just returns.
  132. *
  133. * @param int $size maximum size for the result (optional)
  134. * @return bool for success or failure
  135. * @since 8.1.0
  136. */
  137. public function centerCrop($size = 0);
  138. /**
  139. * Crops the image from point $x$y with dimension $wx$h.
  140. *
  141. * @param int $x Horizontal position
  142. * @param int $y Vertical position
  143. * @param int $w Width
  144. * @param int $h Height
  145. * @return bool for success or failure
  146. * @since 8.1.0
  147. */
  148. public function crop($x, $y, $w, $h);
  149. /**
  150. * Resizes the image to fit within a boundary while preserving ratio.
  151. *
  152. * @param integer $maxWidth
  153. * @param integer $maxHeight
  154. * @return bool
  155. * @since 8.1.0
  156. */
  157. public function fitIn($maxWidth, $maxHeight);
  158. /**
  159. * Shrinks the image to fit within a boundary while preserving ratio.
  160. *
  161. * @param integer $maxWidth
  162. * @param integer $maxHeight
  163. * @return bool
  164. * @since 8.1.0
  165. */
  166. public function scaleDownToFit($maxWidth, $maxHeight);
  167. }