GifsuiteTest.php 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. use Mike42\GfxPhp\Image;
  3. use Mike42\GfxPhp\RgbRasterImage;
  4. use PHPUnit\Framework\TestCase;
  5. use Mike42\GfxPhp\BlackAndWhiteRasterImage;
  6. use Mike42\GfxPhp\GrayscaleRasterImage;
  7. use Mike42\GfxPhp\IndexedRasterImage;
  8. /**
  9. * Simple check that files in the PyGIF test suite can be read, and have the expected dimensions.
  10. */
  11. class GifsuiteTest extends TestCase
  12. {
  13. function loadImage(string $filename) {
  14. return Image::fromFile(__DIR__ . "/../resources/pygif/$filename");
  15. }
  16. function test_255_codes() {
  17. $img = $this -> loadImage("255-codes.gif");
  18. $this -> assertEquals(100, $img -> getWidth());
  19. $this -> assertEquals(100, $img -> getHeight());
  20. }
  21. function test_4095_codes_clear() {
  22. $img = $this -> loadImage("4095-codes-clear.gif");
  23. $this -> assertEquals(100, $img -> getWidth());
  24. $this -> assertEquals(100, $img -> getHeight());
  25. }
  26. function test_4095_codes() {
  27. $img = $this -> loadImage("4095-codes.gif");
  28. $this -> assertEquals(100, $img -> getWidth());
  29. $this -> assertEquals(100, $img -> getHeight());
  30. }
  31. function test_all_blues() {
  32. $img = $this -> loadImage("all-blues.gif");
  33. $this -> assertEquals(16, $img -> getWidth());
  34. $this -> assertEquals(16, $img -> getHeight());
  35. }
  36. function test_all_greens() {
  37. $img = $this -> loadImage("all-greens.gif");
  38. $this -> assertEquals(16, $img -> getWidth());
  39. $this -> assertEquals(16, $img -> getHeight());
  40. }
  41. function test_all_reds() {
  42. $img = $this -> loadImage("all-reds.gif");
  43. $this -> assertEquals(16, $img -> getWidth());
  44. $this -> assertEquals(16, $img -> getHeight());
  45. }
  46. function test_animation() {
  47. $img = $this -> loadImage("animation.gif");
  48. $this -> assertEquals(2, $img -> getWidth());
  49. $this -> assertEquals(2, $img -> getHeight());
  50. }
  51. function test_animation_multi_image_explicit_zero_delay() {
  52. $img = $this -> loadImage("animation-multi-image-explicit-zero-delay.gif");
  53. $this -> assertEquals(2, $img -> getWidth());
  54. $this -> assertEquals(2, $img -> getHeight());
  55. }
  56. function test_animation_multi_image() {
  57. $img = $this -> loadImage("animation-multi-image.gif");
  58. $this -> assertEquals(2, $img -> getWidth());
  59. $this -> assertEquals(2, $img -> getHeight());
  60. }
  61. function test_animation_no_delays() {
  62. $img = $this -> loadImage("animation-no-delays.gif");
  63. $this -> assertEquals(2, $img -> getWidth());
  64. $this -> assertEquals(2, $img -> getHeight());
  65. }
  66. function test_animation_speed() {
  67. $img = $this -> loadImage("animation-speed.gif");
  68. $this -> assertEquals(2, $img -> getWidth());
  69. $this -> assertEquals(2, $img -> getHeight());
  70. }
  71. function test_animation_zero_delays() {
  72. $img = $this -> loadImage("animation-zero-delays.gif");
  73. $this -> assertEquals(2, $img -> getWidth());
  74. $this -> assertEquals(2, $img -> getHeight());
  75. }
  76. function test_comment() {
  77. $img = $this -> loadImage("comment.gif");
  78. $this -> assertEquals(1, $img -> getWidth());
  79. $this -> assertEquals(1, $img -> getHeight());
  80. }
  81. function test_depth1() {
  82. $img = $this -> loadImage("depth1.gif");
  83. $this -> assertEquals(1, $img -> getWidth());
  84. $this -> assertEquals(1, $img -> getHeight());
  85. }
  86. function test_depth2() {
  87. $img = $this -> loadImage("depth2.gif");
  88. $this -> assertEquals(1, $img -> getWidth());
  89. $this -> assertEquals(1, $img -> getHeight());
  90. }
  91. function test_depth3() {
  92. $img = $this -> loadImage("depth3.gif");
  93. $this -> assertEquals(1, $img -> getWidth());
  94. $this -> assertEquals(1, $img -> getHeight());
  95. }
  96. function test_depth4() {
  97. $img = $this -> loadImage("depth4.gif");
  98. $this -> assertEquals(1, $img -> getWidth());
  99. $this -> assertEquals(1, $img -> getHeight());
  100. }
  101. function test_depth5() {
  102. $img = $this -> loadImage("depth5.gif");
  103. $this -> assertEquals(1, $img -> getWidth());
  104. $this -> assertEquals(1, $img -> getHeight());
  105. }
  106. function test_depth6() {
  107. $img = $this -> loadImage("depth6.gif");
  108. $this -> assertEquals(1, $img -> getWidth());
  109. $this -> assertEquals(1, $img -> getHeight());
  110. }
  111. function test_depth7() {
  112. $img = $this -> loadImage("depth7.gif");
  113. $this -> assertEquals(1, $img -> getWidth());
  114. $this -> assertEquals(1, $img -> getHeight());
  115. }
  116. function test_depth8() {
  117. $img = $this -> loadImage("depth8.gif");
  118. $this -> assertEquals(1, $img -> getWidth());
  119. $this -> assertEquals(1, $img -> getHeight());
  120. }
  121. function test_disabled_transparent() {
  122. $img = $this -> loadImage("disabled-transparent.gif");
  123. $this -> assertEquals(2, $img -> getWidth());
  124. $this -> assertEquals(2, $img -> getHeight());
  125. }
  126. function test_dispose_keep() {
  127. $img = $this -> loadImage("dispose-keep.gif");
  128. $this -> assertEquals(2, $img -> getWidth());
  129. $this -> assertEquals(2, $img -> getHeight());
  130. }
  131. function test_dispose_none() {
  132. $img = $this -> loadImage("dispose-none.gif");
  133. $this -> assertEquals(2, $img -> getWidth());
  134. $this -> assertEquals(2, $img -> getHeight());
  135. }
  136. function test_dispose_restore_background() {
  137. $img = $this -> loadImage("dispose-restore-background.gif");
  138. $this -> assertEquals(1, $img -> getWidth());
  139. $this -> assertEquals(1, $img -> getHeight());
  140. }
  141. function test_dispose_restore_previous() {
  142. $img = $this -> loadImage("dispose-restore-previous.gif");
  143. $this -> assertEquals(2, $img -> getWidth());
  144. $this -> assertEquals(2, $img -> getHeight());
  145. }
  146. function test_double_clears() {
  147. $img = $this -> loadImage("double-clears.gif");
  148. $this -> assertEquals(8, $img -> getWidth());
  149. $this -> assertEquals(8, $img -> getHeight());
  150. }
  151. function test_extra_data() {
  152. $img = $this -> loadImage("extra-data.gif");
  153. $this -> assertEquals(1, $img -> getWidth());
  154. $this -> assertEquals(1, $img -> getHeight());
  155. }
  156. function test_extra_pixels() {
  157. $img = $this -> loadImage("extra-pixels.gif");
  158. $this -> assertEquals(1, $img -> getWidth());
  159. $this -> assertEquals(1, $img -> getHeight());
  160. }
  161. function test_four_colors() {
  162. $img = $this -> loadImage("four-colors.gif");
  163. $this -> assertEquals(2, $img -> getWidth());
  164. $this -> assertEquals(2, $img -> getHeight());
  165. }
  166. function test_gif87a_animation() {
  167. $img = $this -> loadImage("gif87a-animation.gif");
  168. $this -> assertEquals(2, $img -> getWidth());
  169. $this -> assertEquals(2, $img -> getHeight());
  170. }
  171. function test_gif87a() {
  172. $img = $this -> loadImage("gif87a.gif");
  173. $this -> assertEquals(1, $img -> getWidth());
  174. $this -> assertEquals(1, $img -> getHeight());
  175. }
  176. function test_high_color() {
  177. $img = $this -> loadImage("high-color.gif");
  178. $this -> assertEquals(16, $img -> getWidth());
  179. $this -> assertEquals(16, $img -> getHeight());
  180. }
  181. function test_icc_color_profile_empty() {
  182. $img = $this -> loadImage("icc-color-profile-empty.gif");
  183. $this -> assertEquals(1, $img -> getWidth());
  184. $this -> assertEquals(1, $img -> getHeight());
  185. }
  186. function test_icc_color_profile() {
  187. $img = $this -> loadImage("icc-color-profile.gif");
  188. $this -> assertEquals(1, $img -> getWidth());
  189. $this -> assertEquals(1, $img -> getHeight());
  190. }
  191. function test_image_inside_bg() {
  192. $img = $this -> loadImage("image-inside-bg.gif");
  193. $this -> assertEquals(1, $img -> getWidth());
  194. $this -> assertEquals(1, $img -> getHeight());
  195. }
  196. function test_image_outside_bg() {
  197. $img = $this -> loadImage("image-outside-bg.gif");
  198. $this -> assertEquals(2, $img -> getWidth());
  199. $this -> assertEquals(2, $img -> getHeight());
  200. }
  201. function test_image_overlap_bg() {
  202. $img = $this -> loadImage("image-overlap-bg.gif");
  203. $this -> assertEquals(2, $img -> getWidth());
  204. $this -> assertEquals(2, $img -> getHeight());
  205. }
  206. function test_images_combine() {
  207. $img = $this -> loadImage("images-combine.gif");
  208. $this -> assertEquals(1, $img -> getWidth());
  209. $this -> assertEquals(1, $img -> getHeight());
  210. }
  211. function test_images_overlap() {
  212. $img = $this -> loadImage("images-overlap.gif");
  213. $this -> assertEquals(1, $img -> getWidth());
  214. $this -> assertEquals(1, $img -> getHeight());
  215. }
  216. function test_image_zero_height() {
  217. $this -> expectException(Exception::class);
  218. $img = $this -> loadImage("image-zero-height.gif");
  219. }
  220. function test_image_zero_size() {
  221. $this -> expectException(Exception::class);
  222. $img = $this -> loadImage("image-zero-size.gif");
  223. }
  224. function test_image_zero_width() {
  225. $this -> expectException(Exception::class);
  226. $img = $this -> loadImage("image-zero-width.gif");
  227. }
  228. function test_interlace() {
  229. $img = $this -> loadImage("interlace.gif");
  230. $this -> assertEquals(16, $img -> getWidth());
  231. $this -> assertEquals(16, $img -> getHeight());
  232. }
  233. function test_invalid_ascii_comment() {
  234. $img = $this -> loadImage("invalid-ascii-comment.gif");
  235. $this -> assertEquals(1, $img -> getWidth());
  236. $this -> assertEquals(1, $img -> getHeight());
  237. }
  238. function test_invalid_background() {
  239. $img = $this -> loadImage("invalid-background.gif");
  240. $this -> assertEquals(1, $img -> getWidth());
  241. $this -> assertEquals(1, $img -> getHeight());
  242. }
  243. function test_invalid_code() {
  244. $this -> expectException(Exception::class);
  245. $img = $this -> loadImage("invalid-code.gif");
  246. }
  247. function test_invalid_colors() {
  248. $this -> expectException(Exception::class);
  249. $img = $this -> loadImage("invalid-colors.gif");
  250. }
  251. function test_invalid_transparent() {
  252. $img = $this -> loadImage("invalid-transparent.gif");
  253. $this -> assertEquals(2, $img -> getWidth());
  254. $this -> assertEquals(2, $img -> getHeight());
  255. }
  256. function test_invalid_utf8_comment() {
  257. $img = $this -> loadImage("invalid-utf8-comment.gif");
  258. $this -> assertEquals(1, $img -> getWidth());
  259. $this -> assertEquals(1, $img -> getHeight());
  260. }
  261. function test_large_codes() {
  262. $img = $this -> loadImage("large-codes.gif");
  263. $this -> assertEquals(100, $img -> getWidth());
  264. $this -> assertEquals(100, $img -> getHeight());
  265. }
  266. function test_large_comment() {
  267. $img = $this -> loadImage("large-comment.gif");
  268. $this -> assertEquals(1, $img -> getWidth());
  269. $this -> assertEquals(1, $img -> getHeight());
  270. }
  271. function test_local_color_table() {
  272. $img = $this -> loadImage("local-color-table.gif");
  273. $this -> assertEquals(1, $img -> getWidth());
  274. $this -> assertEquals(1, $img -> getHeight());
  275. }
  276. function test_loop_animexts() {
  277. $img = $this -> loadImage("loop-animexts.gif");
  278. $this -> assertEquals(1, $img -> getWidth());
  279. $this -> assertEquals(1, $img -> getHeight());
  280. }
  281. function test_loop_buffer() {
  282. $img = $this -> loadImage("loop-buffer.gif");
  283. $this -> assertEquals(1, $img -> getWidth());
  284. $this -> assertEquals(1, $img -> getHeight());
  285. }
  286. function test_loop_buffer_max() {
  287. $img = $this -> loadImage("loop-buffer_max.gif");
  288. $this -> assertEquals(1, $img -> getWidth());
  289. $this -> assertEquals(1, $img -> getHeight());
  290. }
  291. function test_loop_infinite() {
  292. $img = $this -> loadImage("loop-infinite.gif");
  293. $this -> assertEquals(1, $img -> getWidth());
  294. $this -> assertEquals(1, $img -> getHeight());
  295. }
  296. function test_loop_max() {
  297. $img = $this -> loadImage("loop-max.gif");
  298. $this -> assertEquals(1, $img -> getWidth());
  299. $this -> assertEquals(1, $img -> getHeight());
  300. }
  301. function test_loop_once() {
  302. $img = $this -> loadImage("loop-once.gif");
  303. $this -> assertEquals(1, $img -> getWidth());
  304. $this -> assertEquals(1, $img -> getHeight());
  305. }
  306. function test_many_clears() {
  307. $img = $this -> loadImage("many-clears.gif");
  308. $this -> assertEquals(8, $img -> getWidth());
  309. $this -> assertEquals(8, $img -> getHeight());
  310. }
  311. function test_max_codes() {
  312. $img = $this -> loadImage("max-codes.gif");
  313. $this -> assertEquals(100, $img -> getWidth());
  314. $this -> assertEquals(100, $img -> getHeight());
  315. }
  316. function test_max_height() {
  317. $img = $this -> loadImage("max-height.gif");
  318. $this -> assertEquals(1, $img -> getWidth());
  319. $this -> assertEquals(65535, $img -> getHeight());
  320. }
  321. function test_max_size() {
  322. $this -> expectException(Exception::class);
  323. $img = $this -> loadImage("max-size.gif");
  324. }
  325. function test_max_width() {
  326. $img = $this -> loadImage("max-width.gif");
  327. $this -> assertEquals(65535, $img -> getWidth());
  328. $this -> assertEquals(1, $img -> getHeight());
  329. }
  330. function test_missing_pixels() {
  331. $img = $this -> loadImage("missing-pixels.gif");
  332. $this -> assertEquals(1, $img -> getWidth());
  333. $this -> assertEquals(1, $img -> getHeight());
  334. }
  335. function test_no_clear_and_eoi() {
  336. $img = $this -> loadImage("no-clear-and-eoi.gif");
  337. $this -> assertEquals(2, $img -> getWidth());
  338. $this -> assertEquals(1, $img -> getHeight());
  339. }
  340. function test_no_clear() {
  341. $img = $this -> loadImage("no-clear.gif");
  342. $this -> assertEquals(1, $img -> getWidth());
  343. $this -> assertEquals(1, $img -> getHeight());
  344. }
  345. function test_no_data() {
  346. $this -> expectException(Exception::class);
  347. $img = $this -> loadImage("no-data.gif");
  348. }
  349. function test_no_eoi() {
  350. $img = $this -> loadImage("no-eoi.gif");
  351. $this -> assertEquals(1, $img -> getWidth());
  352. $this -> assertEquals(1, $img -> getHeight());
  353. }
  354. function test_no_global_color_table() {
  355. $img = $this -> loadImage("no-global-color-table.gif");
  356. $this -> assertEquals(1, $img -> getWidth());
  357. $this -> assertEquals(1, $img -> getHeight());
  358. }
  359. function test_nul_application_extension() {
  360. $img = $this -> loadImage("nul-application-extension.gif");
  361. $this -> assertEquals(1, $img -> getWidth());
  362. $this -> assertEquals(1, $img -> getHeight());
  363. }
  364. function test_nul_comment() {
  365. $img = $this -> loadImage("nul-comment.gif");
  366. $this -> assertEquals(1, $img -> getWidth());
  367. $this -> assertEquals(1, $img -> getHeight());
  368. }
  369. function test_plain_text() {
  370. $img = $this -> loadImage("plain-text.gif");
  371. $this -> assertEquals(40, $img -> getWidth());
  372. $this -> assertEquals(8, $img -> getHeight());
  373. }
  374. function test_transparent() {
  375. $img = $this -> loadImage("transparent.gif");
  376. $this -> assertEquals(2, $img -> getWidth());
  377. $this -> assertEquals(2, $img -> getHeight());
  378. }
  379. function test_unknown_application_extension() {
  380. $img = $this -> loadImage("unknown-application-extension.gif");
  381. $this -> assertEquals(1, $img -> getWidth());
  382. $this -> assertEquals(1, $img -> getHeight());
  383. }
  384. function test_unknown_extension() {
  385. $img = $this -> loadImage("unknown-extension.gif");
  386. $this -> assertEquals(1, $img -> getWidth());
  387. $this -> assertEquals(1, $img -> getHeight());
  388. }
  389. function test_xmp_data_empty() {
  390. $img = $this -> loadImage("xmp-data-empty.gif");
  391. $this -> assertEquals(1, $img -> getWidth());
  392. $this -> assertEquals(1, $img -> getHeight());
  393. }
  394. function test_xmp_data() {
  395. $img = $this -> loadImage("xmp-data.gif");
  396. $this -> assertEquals(1, $img -> getWidth());
  397. $this -> assertEquals(1, $img -> getHeight());
  398. }
  399. function test_zero_height() {
  400. $this -> expectException(Exception::class);
  401. $img = $this -> loadImage("zero-height.gif");
  402. }
  403. function test_zero_size() {
  404. $this -> expectException(Exception::class);
  405. $img = $this -> loadImage("zero-size.gif");
  406. }
  407. function test_zero_width() {
  408. $this -> expectException(Exception::class);
  409. $img = $this -> loadImage("zero-width.gif");
  410. }
  411. }