IImage.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 data mimetype
  96. * @since 13.0.0
  97. */
  98. public function dataMimeType();
  99. /**
  100. * @return string Returns the raw image data.
  101. * @since 8.1.0
  102. */
  103. public function data();
  104. /**
  105. * (I'm open for suggestions on better method name ;)
  106. * Get the orientation based on EXIF data.
  107. *
  108. * @return int The orientation or -1 if no EXIF data is available.
  109. * @since 8.1.0
  110. */
  111. public function getOrientation();
  112. /**
  113. * (I'm open for suggestions on better method name ;)
  114. * Fixes orientation based on EXIF data.
  115. *
  116. * @return bool
  117. * @since 8.1.0
  118. */
  119. public function fixOrientation();
  120. /**
  121. * Resizes the image preserving ratio.
  122. *
  123. * @param integer $maxSize The maximum size of either the width or height.
  124. * @return bool
  125. * @since 8.1.0
  126. */
  127. public function resize($maxSize);
  128. /**
  129. * @param int $width
  130. * @param int $height
  131. * @return bool
  132. * @since 8.1.0
  133. */
  134. public function preciseResize(int $width, int $height): bool;
  135. /**
  136. * Crops the image to the middle square. If the image is already square it just returns.
  137. *
  138. * @param int $size maximum size for the result (optional)
  139. * @return bool for success or failure
  140. * @since 8.1.0
  141. */
  142. public function centerCrop($size = 0);
  143. /**
  144. * Crops the image from point $x$y with dimension $wx$h.
  145. *
  146. * @param int $x Horizontal position
  147. * @param int $y Vertical position
  148. * @param int $w Width
  149. * @param int $h Height
  150. * @return bool for success or failure
  151. * @since 8.1.0
  152. */
  153. public function crop(int $x, int $y, int $w, int $h): bool;
  154. /**
  155. * Resizes the image to fit within a boundary while preserving ratio.
  156. *
  157. * @param integer $maxWidth
  158. * @param integer $maxHeight
  159. * @return bool
  160. * @since 8.1.0
  161. */
  162. public function fitIn($maxWidth, $maxHeight);
  163. /**
  164. * Shrinks the image to fit within a boundary while preserving ratio.
  165. *
  166. * @param integer $maxWidth
  167. * @param integer $maxHeight
  168. * @return bool
  169. * @since 8.1.0
  170. */
  171. public function scaleDownToFit($maxWidth, $maxHeight);
  172. }