1
0

IImage.php 4.2 KB

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