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

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