AdapterInterface.php 7.0 KB

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