/vendor/intervention/image/tests/GdSystemTest.php

https://gitlab.com/techniconline/kmc · PHP · 1106 lines · 998 code · 90 blank · 18 comment · 0 complexity · 7ce52d28c4b43da27ad86cee269b094e MD5 · raw file

  1. <?php
  2. class GdSystemTest extends PHPUnit_Framework_TestCase
  3. {
  4. public function testMakeFromPath()
  5. {
  6. $img = $this->manager()->make('tests/images/circle.png');
  7. $this->assertInstanceOf('Intervention\Image\Image', $img);
  8. $this->assertInternalType('resource', $img->getCore());
  9. $this->assertInternalType('resource', $img->getCore());
  10. $this->assertInternalType('int', $img->getWidth());
  11. $this->assertInternalType('int', $img->getHeight());
  12. $this->assertEquals(50, $img->getWidth());
  13. $this->assertEquals(50, $img->getHeight());
  14. $this->assertEquals('image/png', $img->mime);
  15. $this->assertEquals('tests/images', $img->dirname);
  16. $this->assertEquals('circle.png', $img->basename);
  17. $this->assertEquals('png', $img->extension);
  18. $this->assertEquals('circle', $img->filename);
  19. $this->assertEquals('image/png', $img->mime);
  20. }
  21. public function testMakeFromString()
  22. {
  23. $str = file_get_contents('tests/images/circle.png');
  24. $img = $this->manager()->make($str);
  25. $this->assertInstanceOf('Intervention\Image\Image', $img);
  26. $this->assertInternalType('resource', $img->getCore());
  27. $this->assertInternalType('int', $img->getWidth());
  28. $this->assertInternalType('int', $img->getHeight());
  29. $this->assertEquals(50, $img->getWidth());
  30. $this->assertEquals(50, $img->getHeight());
  31. $this->assertEquals('image/png', $img->mime);
  32. }
  33. public function testMakeFromResource()
  34. {
  35. $resource = imagecreatefrompng('tests/images/circle.png');
  36. $img = $this->manager()->make($resource);
  37. $this->assertInstanceOf('Intervention\Image\Image', $img);
  38. $this->assertInternalType('resource', $img->getCore());
  39. $this->assertInternalType('int', $img->getWidth());
  40. $this->assertInternalType('int', $img->getHeight());
  41. $this->assertEquals(50, $img->getWidth());
  42. $this->assertEquals(50, $img->getHeight());
  43. }
  44. public function testMakeFromDataUrl()
  45. {
  46. $img = $this->manager()->make('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC');
  47. $this->assertInstanceOf('Intervention\Image\Image', $img);
  48. $this->assertInternalType('resource', $img->getCore());
  49. $this->assertInternalType('int', $img->getWidth());
  50. $this->assertInternalType('int', $img->getHeight());
  51. $this->assertEquals(10, $img->getWidth());
  52. $this->assertEquals(10, $img->getHeight());
  53. }
  54. public function testMakeFromBase64()
  55. {
  56. $img = $this->manager()->make('iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGElEQVQYlWM8c+bMfwYiABMxikYVUk8hAHWzA3cRvs4UAAAAAElFTkSuQmCC');
  57. $this->assertInstanceOf('Intervention\Image\Image', $img);
  58. $this->assertInternalType('resource', $img->getCore());
  59. $this->assertInternalType('int', $img->getWidth());
  60. $this->assertInternalType('int', $img->getHeight());
  61. $this->assertEquals(10, $img->getWidth());
  62. $this->assertEquals(10, $img->getHeight());
  63. }
  64. public function testCanvas()
  65. {
  66. $img = $this->manager()->canvas(30, 20);
  67. $this->assertInstanceOf('Intervention\Image\Image', $img);
  68. $this->assertInternalType('resource', $img->getCore());
  69. $this->assertInternalType('int', $img->getWidth());
  70. $this->assertInternalType('int', $img->getHeight());
  71. $this->assertEquals(30, $img->getWidth());
  72. $this->assertEquals(20, $img->getHeight());
  73. $this->assertTransparentPosition($img, 0, 0);
  74. }
  75. public function testCanvasWithSolidBackground()
  76. {
  77. $img = $this->manager()->canvas(30, 20, 'b53717');
  78. $this->assertInstanceOf('Intervention\Image\Image', $img);
  79. $this->assertInternalType('resource', $img->getCore());
  80. $this->assertInternalType('int', $img->getWidth());
  81. $this->assertInternalType('int', $img->getHeight());
  82. $this->assertEquals(30, $img->getWidth());
  83. $this->assertEquals(20, $img->getHeight());
  84. $this->assertEquals('#b53717', $img->pickColor(15, 15, 'hex'));
  85. }
  86. public function testGetSize()
  87. {
  88. $img = $this->manager()->make('tests/images/tile.png');
  89. $size = $img->getSize();
  90. $this->assertInstanceOf('Intervention\Image\Size', $size);
  91. $this->assertInternalType('int', $size->width);
  92. $this->assertInternalType('int', $size->height);
  93. $this->assertEquals(16, $size->width);
  94. $this->assertEquals(16, $size->height);
  95. }
  96. public function testResizeImage()
  97. {
  98. $img = $this->manager()->make('tests/images/circle.png');
  99. $img->resize(120, 150);
  100. $this->assertInstanceOf('Intervention\Image\Image', $img);
  101. $this->assertInternalType('resource', $img->getCore());
  102. $this->assertInternalType('int', $img->getWidth());
  103. $this->assertInternalType('int', $img->getHeight());
  104. $this->assertEquals(120, $img->getWidth());
  105. $this->assertEquals(150, $img->getHeight());
  106. $this->assertTransparentPosition($img, 0, 0);
  107. }
  108. public function testResizeImageOnlyWidth()
  109. {
  110. $img = $this->manager()->make('tests/images/tile.png');
  111. $img->resize(120, null);
  112. $this->assertInstanceOf('Intervention\Image\Image', $img);
  113. $this->assertInternalType('resource', $img->getCore());
  114. $this->assertInternalType('int', $img->getWidth());
  115. $this->assertInternalType('int', $img->getHeight());
  116. $this->assertEquals(120, $img->getWidth());
  117. $this->assertEquals(16, $img->getHeight());
  118. $this->assertTransparentPosition($img, 0, 15);
  119. }
  120. public function testResizeImageOnlyHeight()
  121. {
  122. $img = $this->manager()->make('tests/images/tile.png');
  123. $img->resize(null, 150);
  124. $this->assertInstanceOf('Intervention\Image\Image', $img);
  125. $this->assertInternalType('resource', $img->getCore());
  126. $this->assertInternalType('int', $img->getWidth());
  127. $this->assertInternalType('int', $img->getHeight());
  128. $this->assertEquals(16, $img->getWidth());
  129. $this->assertEquals(150, $img->getHeight());
  130. $this->assertTransparentPosition($img, 15, 0);
  131. }
  132. public function testResizeImageAutoHeight()
  133. {
  134. $img = $this->manager()->make('tests/images/tile.png');
  135. $img->resize(50, null, function ($constraint) {
  136. $constraint->aspectRatio();
  137. });
  138. $this->assertInstanceOf('Intervention\Image\Image', $img);
  139. $this->assertInternalType('resource', $img->getCore());
  140. $this->assertInternalType('int', $img->getWidth());
  141. $this->assertInternalType('int', $img->getHeight());
  142. $this->assertEquals(50, $img->getWidth());
  143. $this->assertEquals(50, $img->getHeight());
  144. $this->assertTransparentPosition($img, 30, 0);
  145. }
  146. public function testResizeImageAutoWidth()
  147. {
  148. $img = $this->manager()->make('tests/images/tile.png');
  149. $img->resize(null, 50, function ($constraint) {
  150. $constraint->aspectRatio();
  151. });
  152. $this->assertInstanceOf('Intervention\Image\Image', $img);
  153. $this->assertInternalType('resource', $img->getCore());
  154. $this->assertInternalType('int', $img->getWidth());
  155. $this->assertInternalType('int', $img->getHeight());
  156. $this->assertEquals(50, $img->getWidth());
  157. $this->assertEquals(50, $img->getHeight());
  158. $this->assertTransparentPosition($img, 30, 0);
  159. }
  160. public function testResizeDominantWidth()
  161. {
  162. $img = $this->manager()->make('tests/images/tile.png');
  163. $img->resize(100, 120, function ($constraint) {
  164. $constraint->aspectRatio();
  165. });
  166. $this->assertInstanceOf('Intervention\Image\Image', $img);
  167. $this->assertInternalType('resource', $img->getCore());
  168. $this->assertInternalType('int', $img->getWidth());
  169. $this->assertInternalType('int', $img->getHeight());
  170. $this->assertEquals(100, $img->getWidth());
  171. $this->assertEquals(100, $img->getHeight());
  172. $this->assertTransparentPosition($img, 60, 0);
  173. }
  174. public function testResizeImagePreserveSimpleUpsizing()
  175. {
  176. $img = $this->manager()->make('tests/images/tile.png');
  177. $img->resize(100, 100, function ($constraint) {
  178. $constraint->aspectRatio();
  179. $constraint->upsize();
  180. });
  181. $this->assertInstanceOf('Intervention\Image\Image', $img);
  182. $this->assertInternalType('resource', $img->getCore());
  183. $this->assertInternalType('int', $img->getWidth());
  184. $this->assertInternalType('int', $img->getHeight());
  185. $this->assertEquals(16, $img->getWidth());
  186. $this->assertEquals(16, $img->getHeight());
  187. $this->assertTransparentPosition($img, 15, 0);
  188. }
  189. public function testWidenImage()
  190. {
  191. $img = $this->manager()->make('tests/images/tile.png');
  192. $img->widen(100);
  193. $this->assertInstanceOf('Intervention\Image\Image', $img);
  194. $this->assertInternalType('resource', $img->getCore());
  195. $this->assertInternalType('int', $img->getWidth());
  196. $this->assertInternalType('int', $img->getHeight());
  197. $this->assertEquals(100, $img->getWidth());
  198. $this->assertEquals(100, $img->getHeight());
  199. $this->assertTransparentPosition($img, 60, 0);
  200. }
  201. public function testWidenImageWithConstraint()
  202. {
  203. $img = $this->manager()->make('tests/images/tile.png');
  204. $img->widen(100, function ($constraint) {
  205. $constraint->upsize();
  206. });
  207. $this->assertInstanceOf('Intervention\Image\Image', $img);
  208. $this->assertInternalType('resource', $img->getCore());
  209. $this->assertInternalType('int', $img->getWidth());
  210. $this->assertInternalType('int', $img->getHeight());
  211. $this->assertEquals(16, $img->getWidth());
  212. $this->assertEquals(16, $img->getHeight());
  213. $this->assertTransparentPosition($img, 8, 0);
  214. }
  215. public function testHeightenImage()
  216. {
  217. $img = $this->manager()->make('tests/images/tile.png');
  218. $img->heighten(100);
  219. $this->assertInstanceOf('Intervention\Image\Image', $img);
  220. $this->assertInternalType('resource', $img->getCore());
  221. $this->assertInternalType('int', $img->getWidth());
  222. $this->assertInternalType('int', $img->getHeight());
  223. $this->assertEquals(100, $img->getWidth());
  224. $this->assertEquals(100, $img->getHeight());
  225. $this->assertTransparentPosition($img, 60, 0);
  226. }
  227. public function testHeightenImageWithConstraint()
  228. {
  229. $img = $this->manager()->make('tests/images/tile.png');
  230. $img->heighten(100, function ($constraint) {
  231. $constraint->upsize();
  232. });
  233. $this->assertInstanceOf('Intervention\Image\Image', $img);
  234. $this->assertInternalType('resource', $img->getCore());
  235. $this->assertInternalType('int', $img->getWidth());
  236. $this->assertInternalType('int', $img->getHeight());
  237. $this->assertEquals(16, $img->getWidth());
  238. $this->assertEquals(16, $img->getHeight());
  239. $this->assertTransparentPosition($img, 8, 0);
  240. }
  241. public function testResizeCanvasCenter()
  242. {
  243. $img = $this->manager()->make('tests/images/tile.png');
  244. $img->resizeCanvas(10, 10);
  245. $this->assertInternalType('int', $img->getWidth());
  246. $this->assertInternalType('int', $img->getHeight());
  247. $this->assertEquals(10, $img->getWidth());
  248. $this->assertEquals(10, $img->getHeight());
  249. $this->assertColorAtPosition('#b4e000', $img, 0, 4);
  250. $this->assertColorAtPosition('#445160', $img, 5, 5);
  251. $this->assertTransparentPosition($img, 0, 5);
  252. $this->assertTransparentPosition($img, 5, 4);
  253. }
  254. public function testResizeCanvasTopLeft()
  255. {
  256. $img = $this->manager()->make('tests/images/tile.png');
  257. $img->resizeCanvas(10, 10, 'top-left');
  258. $this->assertInternalType('int', $img->getWidth());
  259. $this->assertInternalType('int', $img->getHeight());
  260. $this->assertEquals(10, $img->getWidth());
  261. $this->assertEquals(10, $img->getHeight());
  262. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  263. $this->assertColorAtPosition('#445160', $img, 8, 8);
  264. $this->assertTransparentPosition($img, 0, 8);
  265. $this->assertTransparentPosition($img, 8, 7);
  266. }
  267. public function testResizeCanvasTop()
  268. {
  269. $img = $this->manager()->make('tests/images/tile.png');
  270. $img->resizeCanvas(10, 10, 'top');
  271. $this->assertInternalType('int', $img->getWidth());
  272. $this->assertInternalType('int', $img->getHeight());
  273. $this->assertEquals(10, $img->getWidth());
  274. $this->assertEquals(10, $img->getHeight());
  275. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  276. $this->assertColorAtPosition('#445160', $img, 5, 8);
  277. $this->assertTransparentPosition($img, 0, 8);
  278. $this->assertTransparentPosition($img, 5, 7);
  279. }
  280. public function testResizeCanvasTopRight()
  281. {
  282. $img = $this->manager()->make('tests/images/tile.png');
  283. $img->resizeCanvas(10, 10, 'top-right');
  284. $this->assertInternalType('int', $img->getWidth());
  285. $this->assertInternalType('int', $img->getHeight());
  286. $this->assertEquals(10, $img->getWidth());
  287. $this->assertEquals(10, $img->getHeight());
  288. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  289. $this->assertColorAtPosition('#445160', $img, 2, 8);
  290. $this->assertTransparentPosition($img, 0, 8);
  291. $this->assertTransparentPosition($img, 2, 7);
  292. }
  293. public function testResizeCanvasLeft()
  294. {
  295. $img = $this->manager()->make('tests/images/tile.png');
  296. $img->resizeCanvas(10, 10, 'left');
  297. $this->assertInternalType('int', $img->getWidth());
  298. $this->assertInternalType('int', $img->getHeight());
  299. $this->assertEquals(10, $img->getWidth());
  300. $this->assertEquals(10, $img->getHeight());
  301. $this->assertColorAtPosition('#b4e000', $img, 0, 4);
  302. $this->assertColorAtPosition('#445160', $img, 8, 5);
  303. $this->assertTransparentPosition($img, 0, 5);
  304. $this->assertTransparentPosition($img, 8, 4);
  305. }
  306. public function testResizeCanvasRight()
  307. {
  308. $img = $this->manager()->make('tests/images/tile.png');
  309. $img->resizeCanvas(10, 10, 'right');
  310. $this->assertInternalType('int', $img->getWidth());
  311. $this->assertInternalType('int', $img->getHeight());
  312. $this->assertEquals(10, $img->getWidth());
  313. $this->assertEquals(10, $img->getHeight());
  314. $this->assertColorAtPosition('#b4e000', $img, 0, 4);
  315. $this->assertColorAtPosition('#445160', $img, 2, 5);
  316. $this->assertTransparentPosition($img, 0, 5);
  317. $this->assertTransparentPosition($img, 2, 4);
  318. }
  319. public function testResizeCanvasBottomLeft()
  320. {
  321. $img = $this->manager()->make('tests/images/tile.png');
  322. $img->resizeCanvas(10, 10, 'bottom-left');
  323. $this->assertInternalType('int', $img->getWidth());
  324. $this->assertInternalType('int', $img->getHeight());
  325. $this->assertEquals(10, $img->getWidth());
  326. $this->assertEquals(10, $img->getHeight());
  327. $this->assertColorAtPosition('#b4e000', $img, 0, 1);
  328. $this->assertColorAtPosition('#445160', $img, 8, 2);
  329. $this->assertTransparentPosition($img, 0, 2);
  330. $this->assertTransparentPosition($img, 8, 1);
  331. }
  332. public function testResizeCanvasBottomRight()
  333. {
  334. $img = $this->manager()->make('tests/images/tile.png');
  335. $img->resizeCanvas(10, 10, 'bottom-right');
  336. $this->assertInternalType('int', $img->getWidth());
  337. $this->assertInternalType('int', $img->getHeight());
  338. $this->assertEquals(10, $img->getWidth());
  339. $this->assertEquals(10, $img->getHeight());
  340. $this->assertColorAtPosition('#b4e000', $img, 0, 1);
  341. $this->assertColorAtPosition('#445160', $img, 2, 2);
  342. $this->assertTransparentPosition($img, 0, 2);
  343. $this->assertTransparentPosition($img, 2, 1);
  344. }
  345. public function testResizeCanvasBottom()
  346. {
  347. $img = $this->manager()->make('tests/images/tile.png');
  348. $img->resizeCanvas(10, 10, 'bottom');
  349. $this->assertInternalType('int', $img->getWidth());
  350. $this->assertInternalType('int', $img->getHeight());
  351. $this->assertEquals(10, $img->getWidth());
  352. $this->assertEquals(10, $img->getHeight());
  353. $this->assertColorAtPosition('#b4e000', $img, 0, 1);
  354. $this->assertColorAtPosition('#445160', $img, 5, 2);
  355. $this->assertTransparentPosition($img, 0, 2);
  356. $this->assertTransparentPosition($img, 5, 1);
  357. }
  358. public function testResizeCanvasRelativeWithBackground()
  359. {
  360. $img = $this->manager()->make('tests/images/tile.png');
  361. $img->resizeCanvas(4, 4, 'center', true, '#ff00ff');
  362. $this->assertInternalType('int', $img->getWidth());
  363. $this->assertInternalType('int', $img->getHeight());
  364. $this->assertEquals(20, $img->getWidth());
  365. $this->assertEquals(20, $img->getHeight());
  366. $this->assertColorAtPosition('#ff00ff', $img, 0, 0);
  367. $this->assertColorAtPosition('#ff00ff', $img, 19, 19);
  368. $this->assertColorAtPosition('#b4e000', $img, 2, 9);
  369. $this->assertColorAtPosition('#445160', $img, 10, 10);
  370. $this->assertTransparentPosition($img, 2, 10);
  371. $this->assertTransparentPosition($img, 10, 9);
  372. }
  373. public function testResizeCanvasJustWidth()
  374. {
  375. $img = $this->manager()->make('tests/images/tile.png');
  376. $img->resizeCanvas(10, null);
  377. $this->assertInternalType('int', $img->getWidth());
  378. $this->assertInternalType('int', $img->getHeight());
  379. $this->assertEquals(10, $img->getWidth());
  380. $this->assertEquals(16, $img->getHeight());
  381. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  382. $this->assertColorAtPosition('#445160', $img, 5, 8);
  383. $this->assertTransparentPosition($img, 0, 8);
  384. $this->assertTransparentPosition($img, 5, 7);
  385. }
  386. public function testResizeCanvasJustHeight()
  387. {
  388. $img = $this->manager()->make('tests/images/tile.png');
  389. $img->resizeCanvas(null, 10);
  390. $this->assertInternalType('int', $img->getWidth());
  391. $this->assertInternalType('int', $img->getHeight());
  392. $this->assertEquals(16, $img->getWidth());
  393. $this->assertEquals(10, $img->getHeight());
  394. $this->assertColorAtPosition('#b4e000', $img, 0, 4);
  395. $this->assertColorAtPosition('#445160', $img, 8, 5);
  396. $this->assertTransparentPosition($img, 0, 5);
  397. $this->assertTransparentPosition($img, 8, 4);
  398. }
  399. public function testResizeCanvasSmallerWidthLargerHeight()
  400. {
  401. $img = $this->manager()->make('tests/images/tile.png');
  402. $img->resizeCanvas(10, 20);
  403. $this->assertInternalType('int', $img->getWidth());
  404. $this->assertInternalType('int', $img->getHeight());
  405. $this->assertEquals(10, $img->getWidth());
  406. $this->assertEquals(20, $img->getHeight());
  407. $this->assertColorAtPosition('#b4e000', $img, 0, 9);
  408. $this->assertColorAtPosition('#445160', $img, 5, 10);
  409. $this->assertTransparentPosition($img, 0, 10);
  410. $this->assertTransparentPosition($img, 5, 9);
  411. }
  412. public function testResizeCanvasLargerWidthSmallerHeight()
  413. {
  414. $img = $this->manager()->make('tests/images/tile.png');
  415. $img->resizeCanvas(20, 10);
  416. $this->assertInternalType('int', $img->getWidth());
  417. $this->assertInternalType('int', $img->getHeight());
  418. $this->assertEquals(20, $img->getWidth());
  419. $this->assertEquals(10, $img->getHeight());
  420. $this->assertColorAtPosition('#b4e000', $img, 2, 4);
  421. $this->assertColorAtPosition('#445160', $img, 10, 5);
  422. $this->assertTransparentPosition($img, 0, 0);
  423. $this->assertTransparentPosition($img, 2, 5);
  424. $this->assertTransparentPosition($img, 10, 4);
  425. }
  426. public function testResizeCanvasNegative()
  427. {
  428. $img = $this->manager()->make('tests/images/tile.png');
  429. $img->resizeCanvas(-4, -4);
  430. $this->assertInternalType('int', $img->getWidth());
  431. $this->assertInternalType('int', $img->getHeight());
  432. $this->assertEquals(12, $img->getWidth());
  433. $this->assertEquals(12, $img->getHeight());
  434. $this->assertColorAtPosition('#b4e000', $img, 0, 5);
  435. $this->assertColorAtPosition('#445160', $img, 6, 6);
  436. $this->assertTransparentPosition($img, 0, 6);
  437. $this->assertTransparentPosition($img, 6, 5);
  438. }
  439. public function testResizeCanvasLargerHeightAutoWidth()
  440. {
  441. $img = $this->manager()->make('tests/images/tile.png');
  442. $img->resizeCanvas(null, 20, 'bottom-left', false, '#ff00ff');
  443. $this->assertInternalType('int', $img->getWidth());
  444. $this->assertInternalType('int', $img->getHeight());
  445. $this->assertEquals(16, $img->getWidth());
  446. $this->assertEquals(20, $img->getHeight());
  447. $this->assertColorAtPosition('#ff00ff', $img, 0, 0);
  448. $this->assertColorAtPosition('#b4e000', $img, 0, 4);
  449. $this->assertColorAtPosition('#b4e000', $img, 0, 11);
  450. $this->assertColorAtPosition('#445160', $img, 8, 12);
  451. $this->assertTransparentPosition($img, 0, 12);
  452. $this->assertTransparentPosition($img, 8, 11);
  453. }
  454. public function testResizeCanvasBorderNonRelative()
  455. {
  456. $img = $this->manager()->canvas(1, 1, 'ff0000');
  457. $img->resizeCanvas(17, 17, 'center', false, '333333');
  458. $this->assertInternalType('int', $img->getWidth());
  459. $this->assertInternalType('int', $img->getHeight());
  460. $this->assertEquals(17, $img->getWidth());
  461. $this->assertEquals(17, $img->getHeight());
  462. $this->assertColorAtPosition('#333333', $img, 0, 0);
  463. $this->assertColorAtPosition('#333333', $img, 5, 5);
  464. $this->assertColorAtPosition('#333333', $img, 7, 7);
  465. $this->assertColorAtPosition('#ff0000', $img, 8, 8);
  466. }
  467. public function testCropImage()
  468. {
  469. $img = $this->manager()->make('tests/images/tile.png');
  470. $img->crop(6, 6); // should be centered without pos.
  471. $this->assertInternalType('int', $img->getWidth());
  472. $this->assertInternalType('int', $img->getHeight());
  473. $this->assertEquals(6, $img->getWidth());
  474. $this->assertEquals(6, $img->getHeight());
  475. $this->assertColorAtPosition('#b4e000', $img, 0, 2);
  476. $this->assertColorAtPosition('#445160', $img, 3, 3);
  477. $this->assertTransparentPosition($img, 0, 3);
  478. $this->assertTransparentPosition($img, 3, 2);
  479. }
  480. public function testCropImageWithPosition()
  481. {
  482. $img = $this->manager()->make('tests/images/tile.png');
  483. $img->crop(4, 4, 7, 7); // should be centered without pos.
  484. $this->assertInternalType('int', $img->getWidth());
  485. $this->assertInternalType('int', $img->getHeight());
  486. $this->assertEquals(4, $img->getWidth());
  487. $this->assertEquals(4, $img->getHeight());
  488. $this->assertColorAtPosition('#b4e000', $img, 0, 0);
  489. $this->assertColorAtPosition('#445160', $img, 1, 1);
  490. $this->assertTransparentPosition($img, 0, 1);
  491. $this->assertTransparentPosition($img, 1, 0);
  492. }
  493. public function testFitImageSquare()
  494. {
  495. $img = $this->manager()->make('tests/images/tile.png');
  496. $img->fit(6);
  497. $this->assertInternalType('int', $img->getWidth());
  498. $this->assertInternalType('int', $img->getHeight());
  499. $this->assertEquals(6, $img->getWidth());
  500. $this->assertEquals(6, $img->getHeight());
  501. $this->assertColorAtPosition('#b4e000', $img, 0, 2);
  502. $this->assertColorAtPosition('#445060', $img, 3, 3);
  503. $this->assertTransparentPosition($img, 0, 3);
  504. $this->assertTransparentPosition($img, 3, 2);
  505. }
  506. public function testFitImageRectangle()
  507. {
  508. $img = $this->manager()->make('tests/images/tile.png');
  509. $img->fit(12, 6);
  510. $this->assertInternalType('int', $img->getWidth());
  511. $this->assertInternalType('int', $img->getHeight());
  512. $this->assertEquals(12, $img->getWidth());
  513. $this->assertEquals(6, $img->getHeight());
  514. $this->assertColorAtPosition('#b4e000', $img, 0, 2);
  515. $this->assertColorAtPosition('#445160', $img, 6, 3);
  516. $this->assertTransparentPosition($img, 0, 3);
  517. $this->assertTransparentPosition($img, 6, 2);
  518. }
  519. public function testFitImageWithConstraintUpsize()
  520. {
  521. $img = $this->manager()->make('tests/images/trim.png');
  522. $img->fit(300, 150, function ($constraint) {
  523. $constraint->upsize();
  524. });
  525. $this->assertInternalType('int', $img->getWidth());
  526. $this->assertInternalType('int', $img->getHeight());
  527. $this->assertEquals(50, $img->getWidth());
  528. $this->assertEquals(25, $img->getHeight());
  529. $this->assertColorAtPosition('#00aef0', $img, 0, 0);
  530. $this->assertColorAtPosition('#afa94c', $img, 17, 0);
  531. $this->assertColorAtPosition('#ffa601', $img, 24, 0);
  532. }
  533. public function testFlipImageHorizontal()
  534. {
  535. $img = $this->manager()->make('tests/images/tile.png');
  536. $img->flip('h');
  537. $this->assertInternalType('int', $img->getWidth());
  538. $this->assertInternalType('int', $img->getHeight());
  539. $this->assertEquals(16, $img->getWidth());
  540. $this->assertEquals(16, $img->getHeight());
  541. $this->assertColorAtPosition('#b4e000', $img, 8, 7);
  542. $this->assertColorAtPosition('#445160', $img, 0, 8);
  543. $this->assertTransparentPosition($img, 0, 7);
  544. $this->assertTransparentPosition($img, 8, 8);
  545. }
  546. public function testFlipImageVertical()
  547. {
  548. $img = $this->manager()->make('tests/images/tile.png');
  549. $img->flip('v');
  550. $this->assertInternalType('int', $img->getWidth());
  551. $this->assertInternalType('int', $img->getHeight());
  552. $this->assertEquals(16, $img->getWidth());
  553. $this->assertEquals(16, $img->getHeight());
  554. $this->assertColorAtPosition('#b4e000', $img, 0, 8);
  555. $this->assertColorAtPosition('#445160', $img, 8, 7);
  556. $this->assertTransparentPosition($img, 0, 7);
  557. $this->assertTransparentPosition($img, 8, 8);
  558. }
  559. public function testRotateImage()
  560. {
  561. $img = $this->manager()->make('tests/images/tile.png');
  562. $img->rotate(90);
  563. $this->assertInternalType('int', $img->getWidth());
  564. $this->assertInternalType('int', $img->getHeight());
  565. $this->assertEquals(16, $img->getWidth());
  566. $this->assertEquals(16, $img->getHeight());
  567. $this->assertColorAtPosition('#b4e000', $img, 0, 8);
  568. $this->assertColorAtPosition('#445160', $img, 8, 7);
  569. $this->assertTransparentPosition($img, 0, 7);
  570. $this->assertTransparentPosition($img, 8, 8);
  571. }
  572. public function testInsertImage()
  573. {
  574. $watermark = $this->manager()->canvas(16, 16, '#0000ff'); // create watermark
  575. // top-left anchor
  576. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  577. $img->insert($watermark, 'top-left', 0, 0);
  578. $this->assertInstanceOf('Intervention\Image\Image', $img);
  579. $this->assertInternalType('int', $img->getWidth());
  580. $this->assertInternalType('int', $img->getHeight());
  581. $this->assertEquals($img->getWidth(), 32);
  582. $this->assertEquals($img->getHeight(), 32);
  583. $this->assertEquals('#0000ff', $img->pickColor(0, 0, 'hex'));
  584. $this->assertEquals('#ff0000', $img->pickColor(16, 16, 'hex'));
  585. // top-left anchor coordinates
  586. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  587. $img->insert($watermark, 'top-left', 10, 10);
  588. $this->assertInstanceOf('Intervention\Image\Image', $img);
  589. $this->assertInternalType('int', $img->getWidth());
  590. $this->assertInternalType('int', $img->getHeight());
  591. $this->assertEquals($img->getWidth(), 32);
  592. $this->assertEquals($img->getHeight(), 32);
  593. $this->assertEquals('#ff0000', $img->pickColor(9, 9, 'hex'));
  594. $this->assertEquals('#0000ff', $img->pickColor(10, 10, 'hex'));
  595. // top anchor
  596. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  597. $img->insert($watermark, 'top', 0, 0);
  598. $this->assertInstanceOf('Intervention\Image\Image', $img);
  599. $this->assertInternalType('int', $img->getWidth());
  600. $this->assertInternalType('int', $img->getHeight());
  601. $this->assertEquals($img->getWidth(), 32);
  602. $this->assertEquals($img->getHeight(), 32);
  603. $this->assertEquals('#ff0000', $img->pickColor(0, 0, 'hex'));
  604. $this->assertEquals('#0000ff', $img->pickColor(23, 15, 'hex'));
  605. // top anchor coordinates
  606. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  607. $img->insert($watermark, 'top', 10, 10);
  608. $this->assertInstanceOf('Intervention\Image\Image', $img);
  609. $this->assertInternalType('int', $img->getWidth());
  610. $this->assertInternalType('int', $img->getHeight());
  611. $this->assertEquals($img->getWidth(), 32);
  612. $this->assertEquals($img->getHeight(), 32);
  613. $this->assertEquals('#0000ff', $img->pickColor(18, 10, 'hex'));
  614. $this->assertEquals('#ff0000', $img->pickColor(31, 26, 'hex'));
  615. // top-right anchor
  616. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  617. $img->insert($watermark, 'top-right', 0, 0);
  618. $this->assertInstanceOf('Intervention\Image\Image', $img);
  619. $this->assertInternalType('int', $img->getWidth());
  620. $this->assertInternalType('int', $img->getHeight());
  621. $this->assertEquals($img->getWidth(), 32);
  622. $this->assertEquals($img->getHeight(), 32);
  623. $this->assertEquals('#ff0000', $img->pickColor(15, 0, 'hex'));
  624. $this->assertEquals('#0000ff', $img->pickColor(31, 0, 'hex'));
  625. // top-right anchor coordinates
  626. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  627. $img->insert($watermark, 'top-right', 10, 10);
  628. $this->assertInstanceOf('Intervention\Image\Image', $img);
  629. $this->assertInternalType('int', $img->getWidth());
  630. $this->assertInternalType('int', $img->getHeight());
  631. $this->assertEquals($img->getWidth(), 32);
  632. $this->assertEquals($img->getHeight(), 32);
  633. $this->assertEquals('#ff0000', $img->pickColor(6, 9, 'hex'));
  634. $this->assertEquals('#0000ff', $img->pickColor(21, 25, 'hex'));
  635. // left anchor
  636. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  637. $img->insert($watermark, 'left', 0, 0);
  638. $this->assertInstanceOf('Intervention\Image\Image', $img);
  639. $this->assertInternalType('int', $img->getWidth());
  640. $this->assertInternalType('int', $img->getHeight());
  641. $this->assertEquals($img->getWidth(), 32);
  642. $this->assertEquals($img->getHeight(), 32);
  643. $this->assertEquals('#0000ff', $img->pickColor(15, 23, 'hex'));
  644. $this->assertEquals('#ff0000', $img->pickColor(0, 7, 'hex'));
  645. // left anchor coordinates
  646. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  647. $img->insert($watermark, 'left', 10, 10);
  648. $this->assertInstanceOf('Intervention\Image\Image', $img);
  649. $this->assertInternalType('int', $img->getWidth());
  650. $this->assertInternalType('int', $img->getHeight());
  651. $this->assertEquals($img->getWidth(), 32);
  652. $this->assertEquals($img->getHeight(), 32);
  653. $this->assertEquals('#ff0000', $img->pickColor(8, 23, 'hex'));
  654. $this->assertEquals('#ff0000', $img->pickColor(10, 7, 'hex'));
  655. $this->assertEquals('#0000ff', $img->pickColor(25, 23, 'hex'));
  656. $this->assertEquals('#0000ff', $img->pickColor(25, 8, 'hex'));
  657. // right anchor
  658. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  659. $img->insert($watermark, 'right', 0, 0);
  660. $this->assertInstanceOf('Intervention\Image\Image', $img);
  661. $this->assertInternalType('int', $img->getWidth());
  662. $this->assertInternalType('int', $img->getHeight());
  663. $this->assertEquals($img->getWidth(), 32);
  664. $this->assertEquals($img->getHeight(), 32);
  665. $this->assertEquals('#0000ff', $img->pickColor(31, 23, 'hex'));
  666. $this->assertEquals('#ff0000', $img->pickColor(15, 15, 'hex'));
  667. // right anchor coordinates
  668. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  669. $img->insert($watermark, 'right', 10, 10);
  670. $this->assertInstanceOf('Intervention\Image\Image', $img);
  671. $this->assertInternalType('int', $img->getWidth());
  672. $this->assertInternalType('int', $img->getHeight());
  673. $this->assertEquals($img->getWidth(), 32);
  674. $this->assertEquals($img->getHeight(), 32);
  675. $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex'));
  676. $this->assertEquals('#ff0000', $img->pickColor(22, 23, 'hex'));
  677. $this->assertEquals('#ff0000', $img->pickColor(21, 7, 'hex'));
  678. $this->assertEquals('#0000ff', $img->pickColor(6, 8, 'hex'));
  679. $this->assertEquals('#0000ff', $img->pickColor(21, 23, 'hex'));
  680. $this->assertEquals('#0000ff', $img->pickColor(6, 23, 'hex'));
  681. // bottom-left anchor
  682. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  683. $img->insert($watermark, 'bottom-left', 0, 0);
  684. $this->assertInstanceOf('Intervention\Image\Image', $img);
  685. $this->assertInternalType('int', $img->getWidth());
  686. $this->assertInternalType('int', $img->getHeight());
  687. $this->assertEquals($img->getWidth(), 32);
  688. $this->assertEquals($img->getHeight(), 32);
  689. $this->assertEquals('#0000ff', $img->pickColor(15, 31, 'hex'));
  690. $this->assertEquals('#ff0000', $img->pickColor(0, 15, 'hex'));
  691. // bottom-left anchor coordinates
  692. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  693. $img->insert($watermark, 'bottom-left', 10, 10);
  694. $this->assertInstanceOf('Intervention\Image\Image', $img);
  695. $this->assertInternalType('int', $img->getWidth());
  696. $this->assertInternalType('int', $img->getHeight());
  697. $this->assertEquals($img->getWidth(), 32);
  698. $this->assertEquals($img->getHeight(), 32);
  699. $this->assertEquals('#0000ff', $img->pickColor(10, 21, 'hex'));
  700. $this->assertEquals('#ff0000', $img->pickColor(9, 20, 'hex'));
  701. // bottom anchor
  702. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  703. $img->insert($watermark, 'bottom', 0, 0);
  704. $this->assertInstanceOf('Intervention\Image\Image', $img);
  705. $this->assertInternalType('int', $img->getWidth());
  706. $this->assertInternalType('int', $img->getHeight());
  707. $this->assertEquals($img->getWidth(), 32);
  708. $this->assertEquals($img->getHeight(), 32);
  709. $this->assertEquals('#0000ff', $img->pickColor(8, 16, 'hex'));
  710. $this->assertEquals('#ff0000', $img->pickColor(8, 15, 'hex'));
  711. // bottom anchor coordinates
  712. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  713. $img->insert($watermark, 'bottom', 10, 10);
  714. $this->assertInstanceOf('Intervention\Image\Image', $img);
  715. $this->assertInternalType('int', $img->getWidth());
  716. $this->assertInternalType('int', $img->getHeight());
  717. $this->assertEquals($img->getWidth(), 32);
  718. $this->assertEquals($img->getHeight(), 32);
  719. $this->assertEquals('#ff0000', $img->pickColor(5, 8, 'hex'));
  720. $this->assertEquals('#ff0000', $img->pickColor(23, 22, 'hex'));
  721. $this->assertEquals('#ff0000', $img->pickColor(24, 21, 'hex'));
  722. $this->assertEquals('#ff0000', $img->pickColor(7, 6, 'hex'));
  723. $this->assertEquals('#0000ff', $img->pickColor(8, 6, 'hex'));
  724. $this->assertEquals('#0000ff', $img->pickColor(23, 21, 'hex'));
  725. $this->assertEquals('#0000ff', $img->pickColor(23, 6, 'hex'));
  726. // bottom-right anchor
  727. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  728. $img->insert($watermark, 'bottom-right', 0, 0);
  729. $this->assertInstanceOf('Intervention\Image\Image', $img);
  730. $this->assertInternalType('int', $img->getWidth());
  731. $this->assertInternalType('int', $img->getHeight());
  732. $this->assertEquals($img->getWidth(), 32);
  733. $this->assertEquals($img->getHeight(), 32);
  734. $this->assertEquals('#0000ff', $img->pickColor(16, 16, 'hex'));
  735. $this->assertEquals('#ff0000', $img->pickColor(15, 16, 'hex'));
  736. // bottom-right anchor coordinates
  737. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  738. $img->insert($watermark, 'bottom-right', 10, 10);
  739. $this->assertInstanceOf('Intervention\Image\Image', $img);
  740. $this->assertInternalType('int', $img->getWidth());
  741. $this->assertInternalType('int', $img->getHeight());
  742. $this->assertEquals($img->getWidth(), 32);
  743. $this->assertEquals($img->getHeight(), 32);
  744. $this->assertEquals('#0000ff', $img->pickColor(21, 21, 'hex'));
  745. $this->assertEquals('#ff0000', $img->pickColor(22, 22, 'hex'));
  746. // center anchor
  747. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  748. $img->insert($watermark, 'center', 0, 0);
  749. $this->assertInstanceOf('Intervention\Image\Image', $img);
  750. $this->assertInternalType('int', $img->getWidth());
  751. $this->assertInternalType('int', $img->getHeight());
  752. $this->assertEquals($img->getWidth(), 32);
  753. $this->assertEquals($img->getHeight(), 32);
  754. $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex'));
  755. $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex'));
  756. // center anchor coordinates / coordinates will be ignored for center
  757. $img = $this->manager()->canvas(32, 32, '#ff0000'); // create canvas
  758. $img->insert($watermark, 'center', 10, 10);
  759. $this->assertInstanceOf('Intervention\Image\Image', $img);
  760. $this->assertInternalType('int', $img->getWidth());
  761. $this->assertInternalType('int', $img->getHeight());
  762. $this->assertEquals($img->getWidth(), 32);
  763. $this->assertEquals($img->getHeight(), 32);
  764. $this->assertEquals('#0000ff', $img->pickColor(23, 23, 'hex'));
  765. $this->assertEquals('#ff0000', $img->pickColor(8, 7, 'hex'));
  766. }
  767. public function testInsertWithAlphaChannel()
  768. {
  769. $img = $this->manager()->canvas(50, 50, 'ff0000');
  770. $img->insert('tests/images/circle.png');
  771. $this->assertColorAtPosition('#ff0000', $img, 0, 0);
  772. $this->assertColorAtPosition('#320000', $img, 30, 30);
  773. }
  774. public function testInsertAfterResize()
  775. {
  776. $img = $this->manager()->make('tests/images/trim.png');
  777. $img->resize(16, 16)->insert('tests/images/tile.png');
  778. $this->assertInternalType('int', $img->getWidth());
  779. $this->assertInternalType('int', $img->getHeight());
  780. $this->assertEquals(16, $img->getWidth());
  781. $this->assertEquals(16, $img->getHeight());
  782. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  783. $this->assertColorAtPosition('#00aef0', $img, 0, 8);
  784. $this->assertColorAtPosition('#445160', $img, 8, 8);
  785. $this->assertColorAtPosition('#ffa601', $img, 8, 7);
  786. }
  787. public function testInsertResource()
  788. {
  789. $resource = imagecreatefrompng('tests/images/tile.png');
  790. $img = $this->manager()->make('tests/images/trim.png');
  791. $img->insert($resource);
  792. $this->assertInstanceOf('Intervention\Image\Image', $img);
  793. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  794. $this->assertColorAtPosition('#00aef0', $img, 0, 8);
  795. $this->assertColorAtPosition('#445160', $img, 8, 8);
  796. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  797. $this->assertColorAtPosition('#ffa601', $img, 24, 24);
  798. }
  799. public function testInsertBinary()
  800. {
  801. $data = file_get_contents('tests/images/tile.png');
  802. $img = $this->manager()->make('tests/images/trim.png');
  803. $img->insert($data);
  804. $this->assertInstanceOf('Intervention\Image\Image', $img);
  805. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  806. $this->assertColorAtPosition('#00aef0', $img, 0, 8);
  807. $this->assertColorAtPosition('#445160', $img, 8, 8);
  808. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  809. $this->assertColorAtPosition('#ffa601', $img, 24, 24);
  810. }
  811. public function testInsertInterventionImage()
  812. {
  813. $obj = $this->manager()->make('tests/images/tile.png');
  814. $img = $this->manager()->make('tests/images/trim.png');
  815. $img->insert($obj);
  816. $this->assertInstanceOf('Intervention\Image\Image', $img);
  817. $this->assertColorAtPosition('#b4e000', $img, 0, 7);
  818. $this->assertColorAtPosition('#00aef0', $img, 0, 8);
  819. $this->assertColorAtPosition('#445160', $img, 8, 8);
  820. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  821. $this->assertColorAtPosition('#ffa601', $img, 24, 24);
  822. }
  823. public function testOpacity()
  824. {
  825. $img = $this->manager()->make('tests/images/tile.png');
  826. $img->opacity(50);
  827. $checkColor = $img->pickColor(7, 7, 'array');
  828. $this->assertEquals($checkColor[0], 180);
  829. $this->assertEquals($checkColor[1], 224);
  830. $this->assertEquals($checkColor[2], 0);
  831. $this->assertEquals($checkColor[3], 0.5);
  832. $checkColor = $img->pickColor(8, 8, 'array');
  833. $this->assertEquals($checkColor[0], 68);
  834. $this->assertEquals($checkColor[1], 81);
  835. $this->assertEquals($checkColor[2], 96);
  836. $this->assertEquals($checkColor[3], 0.5);
  837. $this->assertTransparentPosition($img, 0, 11);
  838. }
  839. public function testMaskImage()
  840. {
  841. $img = $this->manager()->make('tests/images/trim.png');
  842. $img->mask('tests/images/gradient.png');
  843. $this->assertTransparentPosition($img, 0, 0);
  844. $this->assertTransparentPosition($img, 23, 23);
  845. $checkColor = $img->pickColor(23, 24, 'array');
  846. $this->assertEquals($checkColor[0], 255);
  847. $this->assertEquals($checkColor[1], 166);
  848. $this->assertEquals($checkColor[2], 1);
  849. $this->assertEquals($checkColor[3], 0.97);
  850. $checkColor = $img->pickColor(39, 25, 'array');
  851. $this->assertEquals($checkColor[0], 0);
  852. $this->assertEquals($checkColor[1], 174);
  853. $this->assertEquals($checkColor[2], 240);
  854. $this->assertEquals($checkColor[3], 0.32);
  855. }
  856. public function testMaskImageWithAlpha()
  857. {
  858. $img = $this->manager()->make('tests/images/trim.png');
  859. $img->mask('tests/images/star.png', true);
  860. $this->assertTransparentPosition($img, 0, 0);
  861. $this->assertTransparentPosition($img, 16, 16);
  862. $checkColor = $img->pickColor(18, 18, 'array');
  863. $this->assertEquals($checkColor[0], 255);
  864. $this->assertEquals($checkColor[1], 166);
  865. $this->assertEquals($checkColor[2], 1);
  866. $this->assertEquals($checkColor[3], 0.65);
  867. $checkColor = $img->pickColor(24, 10, 'array');
  868. $this->assertEquals($checkColor[0], 0);
  869. $this->assertEquals($checkColor[1], 174);
  870. $this->assertEquals($checkColor[2], 240);
  871. $this->assertEquals($checkColor[3], 0.80);
  872. }
  873. public function testPixelateImage()
  874. {
  875. $img = $this->manager()->make('tests/images/tile.png');
  876. $img->pixelate(20);
  877. $this->assertInstanceOf('Intervention\Image\Image', $img);
  878. }
  879. public function testGreyscaleImage()
  880. {
  881. $img = $this->manager()->make('tests/images/tile.png');
  882. $img->greyscale();
  883. $this->assertInstanceOf('Intervention\Image\Image', $img);
  884. $this->assertTransparentPosition($img, 8, 0);
  885. $this->assertColorAtPosition('#b9b9b9', $img, 0, 0);
  886. }
  887. public function testInvertImage()
  888. {
  889. $img = $this->manager()->make('tests/images/tile.png');
  890. $img->invert();
  891. $this->assertInstanceOf('Intervention\Image\Image', $img);
  892. $this->assertTransparentPosition($img, 8, 0);
  893. $this->assertColorAtPosition('#4b1fff', $img, 0, 0);
  894. }
  895. public function testBlurImage()
  896. {
  897. $img = $this->manager()->make('tests/images/tile.png');
  898. $img->blur(1);
  899. $this->assertInstanceOf('Intervention\Image\Image', $img);
  900. }
  901. public function testFillImageWithColor()
  902. {
  903. $img = $this->manager()->make('tests/images/tile.png');
  904. $img->fill('b53717');
  905. $this->assertColorAtPosition('#b53717', $img, 0, 0);
  906. $this->assertColorAtPosition('#b53717', $img, 15, 15);
  907. }
  908. public function testFillImageWithColorAtPosition()
  909. {
  910. $img = $this->manager()->make('tests/images/tile.png');
  911. $img->fill('b53717', 0, 0);
  912. $this->assertTransparentPosition($img, 0, 8);
  913. $this->assertColorAtPosition('#b53717', $img, 0, 0);
  914. $this->assertColorAtPosition('#445160', $img, 15, 15);
  915. }
  916. public function testFillImageWithResource()
  917. {
  918. $resource = imagecreatefrompng('tests/images/tile.png');
  919. $img = $this->manager()->make('tests/images/trim.png');
  920. $img->fill($resource, 0, 0);
  921. $this->assertColorAtPosition('#b4e000', $img, 0, 0);
  922. $this->assertColorAtPosition('#445160', $img, 8, 8);
  923. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  924. $this->assertColorAtPosition('#ffa601', $img, 20, 20);
  925. }
  926. public function testFillImageWithBinary()
  927. {
  928. $data = file_get_contents('tests/images/tile.png');
  929. $img = $this->manager()->make('tests/images/trim.png');
  930. $img->fill($data, 0, 0);
  931. $this->assertColorAtPosition('#b4e000', $img, 0, 0);
  932. $this->assertColorAtPosition('#445160', $img, 8, 8);
  933. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  934. $this->assertColorAtPosition('#ffa601', $img, 20, 20);
  935. }
  936. public function testFillImageWithInterventionImage()
  937. {
  938. $obj = $this->manager()->make('tests/images/tile.png');
  939. $img = $this->manager()->make('tests/images/trim.png');
  940. $img->fill($obj, 0, 0);
  941. $this->assertColorAtPosition('#b4e000', $img, 0, 0);
  942. $this->assertColorAtPosition('#445160', $img, 8, 8);
  943. $this->assertColorAtPosition('#00aef0', $img, 8, 7);
  944. $this->assertColorAtPosition('#ffa601', $img, 20, 20);
  945. }
  946. public function testPixelImage()
  947. {
  948. $img = $this->manager()->make('tests/images/tile.png');
  949. $coords = array(array(5, 5), array(12, 12));
  950. $img = $img->pixel('fdf5e4', $coords[0][0], $coords[0][1]);
  951. $img = $img->pixel(array(255, 255, 255), $coords[1][0], $coords[1][1]);
  952. $this->assertEquals('#fdf5e4', $img->pickColor($coords[0][0], $coords[0][1], 'hex'));
  953. $this->assertEquals('#ffffff', $img->pickColor($coords[1][0], $coords[1][1], 'hex'));
  954. }
  955. public function testTextImage()
  956. {
  957. $img = $this->manager()->canvas(16, 16, 'ffffff');
  958. $img = $img->text('0', 3, 11);
  959. $this->assertInstanceOf('Intervention\Image\Image', $img);
  960. $this->assertEquals('a9e2b15452b2a4637b65625188d206f6', $img->checksum());
  961. $img = $this->manager()->canvas(16, 16, 'ffffff');
  962. $img = $img->text('0', 8, 2, function ($font) {
  963. $font->align('center');
  964. $font->valign('top');
  965. $font->color('000000');
  966. });
  967. $this->assertInstanceOf('Intervention\Image\Image', $img);
  968. $this->assertEquals('649f3f529d3931c56601155fd2680959', $img->checksum());
  969. $img = $this->manager()->canvas(16, 16, 'ffffff');
  970. $img = $img->text('0', 8, 8, function ($font) {
  971. $font->align('right');
  972. $font->valign('middle');
  973. $font->file(2);
  974. $font->color('000000');
  975. });
  976. $this->assertInstanceOf('Intervention\Image\Image', $img);
  977. $this->assertEquals('c0dda67589c46a90d78a97b891a811ee', $img->checksum());
  978. }
  979. public function testRectangleImage()
  980. {
  981. $img = $this->manager()->canvas(16, 16, 'ffffff');
  982. $img->rectangle(5, 5, 11, 11, function ($draw) {
  983. $draw->background('#ff0000');
  984. $draw->border(1, '#0000ff');
  985. });
  986. $this->assertEquals('e95487dcc29daf371a0e9190bff8dbfe', $img->checksum());
  987. }
  988. public function testLineImage()
  989. {
  990. $img = $this->manager()->canvas(16, 16, 'ffffff');
  991. $img->line(0, 0, 15, 15, function ($draw) {
  992. $draw->color('#ff0000');
  993. });
  994. $this->assertEquals('a6237d34f6e95f30d2fc91a46bd058e6', $img->checksum());
  995. }
  996. public function testEllipseImage()
  997. {
  998. $img = $this->manager()->canvas(16, 16, 'ffffff');
  999. $img->ellipse(12, 8, 8, 8, function ($draw) {
  1000. $draw->background('#ff0000');
  1001. $draw->border(1, '#0000ff');
  1002. });
  1003. $this->assertEquals('080d9dd92ebe22f976c3c703cba33510', $img->checksum());
  1004. }
  1005. public function testCircleImage()
  1006. {
  1007. $img = $this->manager()->canvas(16, 16, 'ffffff');
  1008. $img->circle(12, 8, 8, function ($draw) {
  1009. $draw->background('#ff0000');
  1010. $draw->border(1, '#0000ff');
  1011. });
  1012. $this->assertEquals('c3bff06c20244ba14e898e39ea0efd76', $img->checksum());
  1013. }
  1014. public function testPolygonImage()
  1015. {
  1016. $img = $this->manager()