AdapterInterface.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <?php
  2. namespace Gregwar\Image\Adapter;
  3. use Gregwar\Image\Image;
  4. use Gregwar\Image\Source\Source;
  5. /**
  6. * all the functions / methods to work on images.
  7. *
  8. * if changing anything please also add it to \Gregwar\Image\Image
  9. *
  10. * @author wodka <michael.schramm@gmail.com>
  11. */
  12. interface AdapterInterface
  13. {
  14. /**
  15. * set the image source for the adapter.
  16. *
  17. * @param Source $source
  18. *
  19. * @return $this
  20. */
  21. public function setSource(Source $source);
  22. /**
  23. * get the raw resource.
  24. *
  25. * @return resource
  26. */
  27. public function getResource();
  28. /**
  29. * Gets the name of the adapter.
  30. *
  31. * @return string
  32. */
  33. public function getName();
  34. /**
  35. * Image width.
  36. *
  37. * @return int
  38. */
  39. public function width();
  40. /**
  41. * Image height.
  42. *
  43. * @return int
  44. */
  45. public function height();
  46. /**
  47. * Init the resource.
  48. *
  49. * @return $this
  50. */
  51. public function init();
  52. /**
  53. * Unload the resource
  54. */
  55. public function deinit();
  56. /**
  57. * Save the image as a gif.
  58. *
  59. * @return $this
  60. */
  61. public function saveGif($file);
  62. /**
  63. * Save the image as a png.
  64. *
  65. * @return $this
  66. */
  67. public function savePng($file);
  68. /**
  69. * Save the image as a Webp.
  70. *
  71. * @return $this
  72. */
  73. public function saveWebp($file, $quality);
  74. /**
  75. * Save the image as a jpeg.
  76. *
  77. * @return $this
  78. */
  79. public function saveJpeg($file, $quality);
  80. /**
  81. * Works as resize() excepts that the layout will be cropped.
  82. *
  83. * @param int $width the width
  84. * @param int $height the height
  85. * @param int $background the background
  86. *
  87. * @return $this
  88. */
  89. public function cropResize($width = null, $height = null, $background = 0xffffff);
  90. /**
  91. * Resize the image preserving scale. Can enlarge it.
  92. *
  93. * @param int $width the width
  94. * @param int $height the height
  95. * @param int $background the background
  96. * @param bool $crop
  97. *
  98. * @return $this
  99. */
  100. public function scaleResize($width = null, $height = null, $background = 0xffffff, $crop = false);
  101. /**
  102. * Resizes the image. It will never be enlarged.
  103. *
  104. * @param int $width the width
  105. * @param int $height the height
  106. * @param int $background the background
  107. * @param bool $force
  108. * @param bool $rescale
  109. * @param bool $crop
  110. *
  111. * @return $this
  112. */
  113. public function resize($width = null, $height = null, $background = 0xffffff, $force = false, $rescale = false, $crop = false);
  114. /**
  115. * Crops the image.
  116. *
  117. * @param int $x the top-left x position of the crop box
  118. * @param int $y the top-left y position of the crop box
  119. * @param int $width the width of the crop box
  120. * @param int $height the height of the crop box
  121. *
  122. * @return $this
  123. */
  124. public function crop($x, $y, $width, $height);
  125. /**
  126. * enable progressive image loading.
  127. *
  128. * @return $this
  129. */
  130. public function enableProgressive();
  131. /**
  132. * Resizes the image forcing the destination to have exactly the
  133. * given width and the height.
  134. *
  135. * @param int $width the width
  136. * @param int $height the height
  137. * @param int $background the background
  138. *
  139. * @return $this
  140. */
  141. public function forceResize($width = null, $height = null, $background = 0xffffff);
  142. /**
  143. * Perform a zoom crop of the image to desired width and height.
  144. *
  145. * @param int $width Desired width
  146. * @param int $height Desired height
  147. * @param int $background
  148. *
  149. * @return $this
  150. */
  151. public function zoomCrop($width, $height, $background = 0xffffff);
  152. /**
  153. * Fills the image background to $bg if the image is transparent.
  154. *
  155. * @param int $background background color
  156. *
  157. * @return $this
  158. */
  159. public function fillBackground($background = 0xffffff);
  160. /**
  161. * Negates the image.
  162. *
  163. * @return $this
  164. */
  165. public function negate();
  166. /**
  167. * Changes the brightness of the image.
  168. *
  169. * @param int $brightness the brightness
  170. *
  171. * @return $this
  172. */
  173. public function brightness($brightness);
  174. /**
  175. * Contrasts the image.
  176. *
  177. * @param int $contrast the contrast [-100, 100]
  178. *
  179. * @return $this
  180. */
  181. public function contrast($contrast);
  182. /**
  183. * Apply a grayscale level effect on the image.
  184. *
  185. * @return $this
  186. */
  187. public function grayscale();
  188. /**
  189. * Emboss the image.
  190. *
  191. * @return $this
  192. */
  193. public function emboss();
  194. /**
  195. * Smooth the image.
  196. *
  197. * @param int $p value between [-10,10]
  198. *
  199. * @return $this
  200. */
  201. public function smooth($p);
  202. /**
  203. * Sharps the image.
  204. *
  205. * @return $this
  206. */
  207. public function sharp();
  208. /**
  209. * Edges the image.
  210. *
  211. * @return $this
  212. */
  213. public function edge();
  214. /**
  215. * Colorize the image.
  216. *
  217. * @param int $red value in range [-255, 255]
  218. * @param int $green value in range [-255, 255]
  219. * @param int $blue value in range [-255, 255]
  220. *
  221. * @return $this
  222. */
  223. public function colorize($red, $green, $blue);
  224. /**
  225. * apply sepia to the image.
  226. *
  227. * @return $this
  228. */
  229. public function sepia();
  230. /**
  231. * Merge with another image.
  232. *
  233. * @param Image $other
  234. * @param int $x
  235. * @param int $y
  236. * @param int $width
  237. * @param int $height
  238. *
  239. * @return $this
  240. */
  241. public function merge(Image $other, $x = 0, $y = 0, $width = null, $height = null);
  242. /**
  243. * Rotate the image.
  244. *
  245. * @param float $angle
  246. * @param int $background
  247. *
  248. * @return $this
  249. */
  250. public function rotate($angle, $background = 0xffffff);
  251. /**
  252. * Fills the image.
  253. *
  254. * @param int $color
  255. * @param int $x
  256. * @param int $y
  257. *
  258. * @return $this
  259. */
  260. public function fill($color = 0xffffff, $x = 0, $y = 0);
  261. /**
  262. * write text to the image.
  263. *
  264. * @param string $font
  265. * @param string $text
  266. * @param int $x
  267. * @param int $y
  268. * @param int $size
  269. * @param int $angle
  270. * @param int $color
  271. * @param string $align
  272. */
  273. public function write($font, $text, $x = 0, $y = 0, $size = 12, $angle = 0, $color = 0x000000, $align = 'left');
  274. /**
  275. * Draws a rectangle.
  276. *
  277. * @param int $x1
  278. * @param int $y1
  279. * @param int $x2
  280. * @param int $y2
  281. * @param int $color
  282. * @param bool $filled
  283. *
  284. * @return $this
  285. */
  286. public function rectangle($x1, $y1, $x2, $y2, $color, $filled = false);
  287. /**
  288. * Draws a rounded rectangle.
  289. *
  290. * @param int $x1
  291. * @param int $y1
  292. * @param int $x2
  293. * @param int $y2
  294. * @param int $radius
  295. * @param int $color
  296. * @param bool $filled
  297. *
  298. * @return $this
  299. */
  300. public function roundedRectangle($x1, $y1, $x2, $y2, $radius, $color, $filled = false);
  301. /**
  302. * Draws a line.
  303. *
  304. * @param int $x1
  305. * @param int $y1
  306. * @param int $x2
  307. * @param int $y2
  308. * @param int $color
  309. *
  310. * @return $this
  311. */
  312. public function line($x1, $y1, $x2, $y2, $color = 0x000000);
  313. /**
  314. * Draws an ellipse.
  315. *
  316. * @param int $cx
  317. * @param int $cy
  318. * @param int $width
  319. * @param int $height
  320. * @param int $color
  321. * @param bool $filled
  322. *
  323. * @return $this
  324. */
  325. public function ellipse($cx, $cy, $width, $height, $color = 0x000000, $filled = false);
  326. /**
  327. * Draws a circle.
  328. *
  329. * @param int $cx
  330. * @param int $cy
  331. * @param int $r
  332. * @param int $color
  333. * @param bool $filled
  334. *
  335. * @return $this
  336. */
  337. public function circle($cx, $cy, $r, $color = 0x000000, $filled = false);
  338. /**
  339. * Draws a polygon.
  340. *
  341. * @param array $points
  342. * @param int $color
  343. * @param bool $filled
  344. *
  345. * @return $this
  346. */
  347. public function polygon(array $points, $color, $filled = false);
  348. /**
  349. * Flips the image.
  350. *
  351. * @param int $flipVertical
  352. * @param int $flipHorizontal
  353. *
  354. * @return $this
  355. */
  356. public function flip($flipVertical, $flipHorizontal);
  357. }