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

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