AdapterInterface.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 jpeg.
  70. *
  71. * @return $this
  72. */
  73. public function saveJpeg($file, $quality);
  74. /**
  75. * Works as resize() excepts that the layout will be cropped.
  76. *
  77. * @param int $width the width
  78. * @param int $height the height
  79. * @param int $background the background
  80. *
  81. * @return $this
  82. */
  83. public function cropResize($width = null, $height = null, $background = 0xffffff);
  84. /**
  85. * Resize the image preserving scale. Can enlarge it.
  86. *
  87. * @param int $width the width
  88. * @param int $height the height
  89. * @param int $background the background
  90. * @param bool $crop
  91. *
  92. * @return $this
  93. */
  94. public function scaleResize($width = null, $height = null, $background = 0xffffff, $crop = false);
  95. /**
  96. * Resizes the image. It will never be enlarged.
  97. *
  98. * @param int $width the width
  99. * @param int $height the height
  100. * @param int $background the background
  101. * @param bool $force
  102. * @param bool $rescale
  103. * @param bool $crop
  104. *
  105. * @return $this
  106. */
  107. public function resize($width = null, $height = null, $background = 0xffffff, $force = false, $rescale = false, $crop = false);
  108. /**
  109. * Crops the image.
  110. *
  111. * @param int $x the top-left x position of the crop box
  112. * @param int $y the top-left y position of the crop box
  113. * @param int $width the width of the crop box
  114. * @param int $height the height of the crop box
  115. *
  116. * @return $this
  117. */
  118. public function crop($x, $y, $width, $height);
  119. /**
  120. * enable progressive image loading.
  121. *
  122. * @return $this
  123. */
  124. public function enableProgressive();
  125. /**
  126. * Resizes the image forcing the destination to have exactly the
  127. * given width and the height.
  128. *
  129. * @param int $width the width
  130. * @param int $height the height
  131. * @param int $background the background
  132. *
  133. * @return $this
  134. */
  135. public function forceResize($width = null, $height = null, $background = 0xffffff);
  136. /**
  137. * Perform a zoom crop of the image to desired width and height.
  138. *
  139. * @param int $width Desired width
  140. * @param int $height Desired height
  141. * @param int $background
  142. *
  143. * @return $this
  144. */
  145. public function zoomCrop($width, $height, $background = 0xffffff);
  146. /**
  147. * Fills the image background to $bg if the image is transparent.
  148. *
  149. * @param int $background background color
  150. *
  151. * @return $this
  152. */
  153. public function fillBackground($background = 0xffffff);
  154. /**
  155. * Negates the image.
  156. *
  157. * @return $this
  158. */
  159. public function negate();
  160. /**
  161. * Changes the brightness of the image.
  162. *
  163. * @param int $brightness the brightness
  164. *
  165. * @return $this
  166. */
  167. public function brightness($brightness);
  168. /**
  169. * Contrasts the image.
  170. *
  171. * @param int $contrast the contrast [-100, 100]
  172. *
  173. * @return $this
  174. */
  175. public function contrast($contrast);
  176. /**
  177. * Apply a grayscale level effect on the image.
  178. *
  179. * @return $this
  180. */
  181. public function grayscale();
  182. /**
  183. * Emboss the image.
  184. *
  185. * @return $this
  186. */
  187. public function emboss();
  188. /**
  189. * Smooth the image.
  190. *
  191. * @param int $p value between [-10,10]
  192. *
  193. * @return $this
  194. */
  195. public function smooth($p);
  196. /**
  197. * Sharps the image.
  198. *
  199. * @return $this
  200. */
  201. public function sharp();
  202. /**
  203. * Edges the image.
  204. *
  205. * @return $this
  206. */
  207. public function edge();
  208. /**
  209. * Colorize the image.
  210. *
  211. * @param int $red value in range [-255, 255]
  212. * @param int $green value in range [-255, 255]
  213. * @param int $blue value in range [-255, 255]
  214. *
  215. * @return $this
  216. */
  217. public function colorize($red, $green, $blue);
  218. /**
  219. * apply sepia to the image.
  220. *
  221. * @return $this
  222. */
  223. public function sepia();
  224. /**
  225. * Merge with another image.
  226. *
  227. * @param Image $other
  228. * @param int $x
  229. * @param int $y
  230. * @param int $width
  231. * @param int $height
  232. *
  233. * @return $this
  234. */
  235. public function merge(Image $other, $x = 0, $y = 0, $width = null, $height = null);
  236. /**
  237. * Rotate the image.
  238. *
  239. * @param float $angle
  240. * @param int $background
  241. *
  242. * @return $this
  243. */
  244. public function rotate($angle, $background = 0xffffff);
  245. /**
  246. * Fills the image.
  247. *
  248. * @param int $color
  249. * @param int $x
  250. * @param int $y
  251. *
  252. * @return $this
  253. */
  254. public function fill($color = 0xffffff, $x = 0, $y = 0);
  255. /**
  256. * write text to the image.
  257. *
  258. * @param string $font
  259. * @param string $text
  260. * @param int $x
  261. * @param int $y
  262. * @param int $size
  263. * @param int $angle
  264. * @param int $color
  265. * @param string $align
  266. */
  267. public function write($font, $text, $x = 0, $y = 0, $size = 12, $angle = 0, $color = 0x000000, $align = 'left');
  268. /**
  269. * Draws a rectangle.
  270. *
  271. * @param int $x1
  272. * @param int $y1
  273. * @param int $x2
  274. * @param int $y2
  275. * @param int $color
  276. * @param bool $filled
  277. *
  278. * @return $this
  279. */
  280. public function rectangle($x1, $y1, $x2, $y2, $color, $filled = false);
  281. /**
  282. * Draws a rounded rectangle.
  283. *
  284. * @param int $x1
  285. * @param int $y1
  286. * @param int $x2
  287. * @param int $y2
  288. * @param int $radius
  289. * @param int $color
  290. * @param bool $filled
  291. *
  292. * @return $this
  293. */
  294. public function roundedRectangle($x1, $y1, $x2, $y2, $radius, $color, $filled = false);
  295. /**
  296. * Draws a line.
  297. *
  298. * @param int $x1
  299. * @param int $y1
  300. * @param int $x2
  301. * @param int $y2
  302. * @param int $color
  303. *
  304. * @return $this
  305. */
  306. public function line($x1, $y1, $x2, $y2, $color = 0x000000);
  307. /**
  308. * Draws an ellipse.
  309. *
  310. * @param int $cx
  311. * @param int $cy
  312. * @param int $width
  313. * @param int $height
  314. * @param int $color
  315. * @param bool $filled
  316. *
  317. * @return $this
  318. */
  319. public function ellipse($cx, $cy, $width, $height, $color = 0x000000, $filled = false);
  320. /**
  321. * Draws a circle.
  322. *
  323. * @param int $cx
  324. * @param int $cy
  325. * @param int $r
  326. * @param int $color
  327. * @param bool $filled
  328. *
  329. * @return $this
  330. */
  331. public function circle($cx, $cy, $r, $color = 0x000000, $filled = false);
  332. /**
  333. * Draws a polygon.
  334. *
  335. * @param array $points
  336. * @param int $color
  337. * @param bool $filled
  338. *
  339. * @return $this
  340. */
  341. public function polygon(array $points, $color, $filled = false);
  342. /**
  343. * Flips the image.
  344. *
  345. * @param int $flipVertical
  346. * @param int $flipHorizontal
  347. *
  348. * @return $this
  349. */
  350. public function flip($flipVertical, $flipHorizontal);
  351. }