/vendor/intervention/image/tests/ImagickSystemTest.php

https://gitlab.com/techniconline/kmc · PHP · 1112 lines · 1006 code · 88 blank · 18 comment · 0 complexity · 933e288fffd5dc241d35844a7e96df98 MD5 · raw file

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