/
test_file_gif.py
752 lines (572 loc) · 23.7 KB
/
test_file_gif.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
from .helper import unittest, PillowTestCase, hopper, netpbm_available
from PIL import Image, ImagePalette, GifImagePlugin, ImageDraw
from io import BytesIO
try:
from PIL import _webp
HAVE_WEBP = True
except ImportError:
HAVE_WEBP = False
codecs = dir(Image.core)
# sample gif stream
TEST_GIF = "Tests/images/hopper.gif"
with open(TEST_GIF, "rb") as f:
data = f.read()
class TestFileGif(PillowTestCase):
def setUp(self):
if "gif_encoder" not in codecs or "gif_decoder" not in codecs:
self.skipTest("gif support not available") # can this happen?
def test_sanity(self):
im = Image.open(TEST_GIF)
im.load()
self.assertEqual(im.mode, "P")
self.assertEqual(im.size, (128, 128))
self.assertEqual(im.format, "GIF")
self.assertEqual(im.info["version"], b"GIF89a")
def test_unclosed_file(self):
def open():
im = Image.open(TEST_GIF)
im.load()
self.assert_warning(None, open)
def test_invalid_file(self):
invalid_file = "Tests/images/flower.jpg"
self.assertRaises(SyntaxError, GifImagePlugin.GifImageFile, invalid_file)
def test_optimize(self):
def test_grayscale(optimize):
im = Image.new("L", (1, 1), 0)
filename = BytesIO()
im.save(filename, "GIF", optimize=optimize)
return len(filename.getvalue())
def test_bilevel(optimize):
im = Image.new("1", (1, 1), 0)
test_file = BytesIO()
im.save(test_file, "GIF", optimize=optimize)
return len(test_file.getvalue())
self.assertEqual(test_grayscale(0), 800)
self.assertEqual(test_grayscale(1), 44)
self.assertEqual(test_bilevel(0), 800)
self.assertEqual(test_bilevel(1), 800)
def test_optimize_correctness(self):
# 256 color Palette image, posterize to > 128 and < 128 levels
# Size bigger and smaller than 512x512
# Check the palette for number of colors allocated.
# Check for correctness after conversion back to RGB
def check(colors, size, expected_palette_length):
# make an image with empty colors in the start of the palette range
im = Image.frombytes(
"P",
(colors, colors),
bytes(bytearray(range(256 - colors, 256)) * colors),
)
im = im.resize((size, size))
outfile = BytesIO()
im.save(outfile, "GIF")
outfile.seek(0)
reloaded = Image.open(outfile)
# check palette length
palette_length = max(i + 1 for i, v in enumerate(reloaded.histogram()) if v)
self.assertEqual(expected_palette_length, palette_length)
self.assert_image_equal(im.convert("RGB"), reloaded.convert("RGB"))
# These do optimize the palette
check(128, 511, 128)
check(64, 511, 64)
check(4, 511, 4)
# These don't optimize the palette
check(128, 513, 256)
check(64, 513, 256)
check(4, 513, 256)
# other limits that don't optimize the palette
check(129, 511, 256)
check(255, 511, 256)
check(256, 511, 256)
def test_optimize_full_l(self):
im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256))))
test_file = BytesIO()
im.save(test_file, "GIF", optimize=True)
self.assertEqual(im.mode, "L")
def test_roundtrip(self):
out = self.tempfile("temp.gif")
im = hopper()
im.save(out)
reread = Image.open(out)
self.assert_image_similar(reread.convert("RGB"), im, 50)
def test_roundtrip2(self):
# see https://github.com/python-pillow/Pillow/issues/403
out = self.tempfile("temp.gif")
im = Image.open(TEST_GIF)
im2 = im.copy()
im2.save(out)
reread = Image.open(out)
self.assert_image_similar(reread.convert("RGB"), hopper(), 50)
def test_roundtrip_save_all(self):
# Single frame image
out = self.tempfile("temp.gif")
im = hopper()
im.save(out, save_all=True)
reread = Image.open(out)
self.assert_image_similar(reread.convert("RGB"), im, 50)
# Multiframe image
im = Image.open("Tests/images/dispose_bgnd.gif")
out = self.tempfile("temp.gif")
im.save(out, save_all=True)
reread = Image.open(out)
self.assertEqual(reread.n_frames, 5)
def test_headers_saving_for_animated_gifs(self):
important_headers = ["background", "version", "duration", "loop"]
# Multiframe image
im = Image.open("Tests/images/dispose_bgnd.gif")
info = im.info.copy()
out = self.tempfile("temp.gif")
im.save(out, save_all=True)
reread = Image.open(out)
for header in important_headers:
self.assertEqual(info[header], reread.info[header])
def test_palette_handling(self):
# see https://github.com/python-pillow/Pillow/issues/513
im = Image.open(TEST_GIF)
im = im.convert("RGB")
im = im.resize((100, 100), Image.LANCZOS)
im2 = im.convert("P", palette=Image.ADAPTIVE, colors=256)
f = self.tempfile("temp.gif")
im2.save(f, optimize=True)
reloaded = Image.open(f)
self.assert_image_similar(im, reloaded.convert("RGB"), 10)
def test_palette_434(self):
# see https://github.com/python-pillow/Pillow/issues/434
def roundtrip(im, *args, **kwargs):
out = self.tempfile("temp.gif")
im.copy().save(out, *args, **kwargs)
reloaded = Image.open(out)
return reloaded
orig = "Tests/images/test.colors.gif"
im = Image.open(orig)
self.assert_image_similar(im, roundtrip(im), 1)
self.assert_image_similar(im, roundtrip(im, optimize=True), 1)
im = im.convert("RGB")
# check automatic P conversion
reloaded = roundtrip(im).convert("RGB")
self.assert_image_equal(im, reloaded)
@unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_bmp_mode(self):
img = Image.open(TEST_GIF).convert("RGB")
tempfile = self.tempfile("temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile)
self.assert_image_similar(img, Image.open(tempfile).convert("RGB"), 0)
@unittest.skipUnless(netpbm_available(), "netpbm not available")
def test_save_netpbm_l_mode(self):
img = Image.open(TEST_GIF).convert("L")
tempfile = self.tempfile("temp.gif")
GifImagePlugin._save_netpbm(img, 0, tempfile)
self.assert_image_similar(img, Image.open(tempfile).convert("L"), 0)
def test_seek(self):
img = Image.open("Tests/images/dispose_none.gif")
framecount = 0
try:
while True:
framecount += 1
img.seek(img.tell() + 1)
except EOFError:
self.assertEqual(framecount, 5)
def test_seek_info(self):
im = Image.open("Tests/images/iss634.gif")
info = im.info.copy()
im.seek(1)
im.seek(0)
self.assertEqual(im.info, info)
def test_seek_rewind(self):
im = Image.open("Tests/images/iss634.gif")
im.seek(2)
im.seek(1)
expected = Image.open("Tests/images/iss634.gif")
expected.seek(1)
self.assert_image_equal(im, expected)
def test_n_frames(self):
for path, n_frames in [[TEST_GIF, 1], ["Tests/images/iss634.gif", 42]]:
# Test is_animated before n_frames
im = Image.open(path)
self.assertEqual(im.is_animated, n_frames != 1)
# Test is_animated after n_frames
im = Image.open(path)
self.assertEqual(im.n_frames, n_frames)
self.assertEqual(im.is_animated, n_frames != 1)
def test_eoferror(self):
im = Image.open(TEST_GIF)
n_frames = im.n_frames
# Test seeking past the last frame
self.assertRaises(EOFError, im.seek, n_frames)
self.assertLess(im.tell(), n_frames)
# Test that seeking to the last frame does not raise an error
im.seek(n_frames - 1)
def test_dispose_none(self):
img = Image.open("Tests/images/dispose_none.gif")
try:
while True:
img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, 1)
except EOFError:
pass
def test_dispose_background(self):
img = Image.open("Tests/images/dispose_bgnd.gif")
try:
while True:
img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, 2)
except EOFError:
pass
def test_dispose_previous(self):
img = Image.open("Tests/images/dispose_prev.gif")
try:
while True:
img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, 3)
except EOFError:
pass
def test_save_dispose(self):
out = self.tempfile("temp.gif")
im_list = [
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#111"),
Image.new("L", (100, 100), "#222"),
]
for method in range(0, 4):
im_list[0].save(
out, save_all=True, append_images=im_list[1:], disposal=method
)
img = Image.open(out)
for _ in range(2):
img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, method)
# check per frame disposal
im_list[0].save(
out,
save_all=True,
append_images=im_list[1:],
disposal=tuple(range(len(im_list))),
)
img = Image.open(out)
for i in range(2):
img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, i + 1)
def test_dispose2_palette(self):
out = self.tempfile("temp.gif")
# 4 backgrounds: White, Grey, Black, Red
circles = [(255, 255, 255), (153, 153, 153), (0, 0, 0), (255, 0, 0)]
im_list = []
for circle in circles:
img = Image.new("RGB", (100, 100), (255, 0, 0))
# Red circle in center of each frame
d = ImageDraw.Draw(img)
d.ellipse([(40, 40), (60, 60)], fill=circle)
im_list.append(img)
im_list[0].save(out, save_all=True, append_images=im_list[1:], disposal=2)
img = Image.open(out)
for i, circle in enumerate(circles):
img.seek(i)
rgb_img = img.convert("RGB")
# Check top left pixel matches background
self.assertEqual(rgb_img.getpixel((0, 0)), (255, 0, 0))
# Center remains red every frame
self.assertEqual(rgb_img.getpixel((50, 50)), circle)
def test_dispose2_diff(self):
out = self.tempfile("temp.gif")
# 4 frames: red/blue, red/red, blue/blue, red/blue
circles = [
((255, 0, 0, 255), (0, 0, 255, 255)),
((255, 0, 0, 255), (255, 0, 0, 255)),
((0, 0, 255, 255), (0, 0, 255, 255)),
((255, 0, 0, 255), (0, 0, 255, 255)),
]
im_list = []
for i in range(len(circles)):
# Transparent BG
img = Image.new("RGBA", (100, 100), (255, 255, 255, 0))
# Two circles per frame
d = ImageDraw.Draw(img)
d.ellipse([(0, 30), (40, 70)], fill=circles[i][0])
d.ellipse([(60, 30), (100, 70)], fill=circles[i][1])
im_list.append(img)
im_list[0].save(
out, save_all=True, append_images=im_list[1:], disposal=2, transparency=0
)
img = Image.open(out)
for i, colours in enumerate(circles):
img.seek(i)
rgb_img = img.convert("RGBA")
# Check left circle is correct colour
self.assertEqual(rgb_img.getpixel((20, 50)), colours[0])
# Check right circle is correct colour
self.assertEqual(rgb_img.getpixel((80, 50)), colours[1])
# Check BG is correct colour
self.assertEqual(rgb_img.getpixel((1, 1)), (255, 255, 255, 0))
def test_dispose2_background(self):
out = self.tempfile("temp.gif")
im_list = []
im = Image.new("P", (100, 100))
d = ImageDraw.Draw(im)
d.rectangle([(50, 0), (100, 100)], fill="#f00")
d.rectangle([(0, 0), (50, 100)], fill="#0f0")
im_list.append(im)
im = Image.new("P", (100, 100))
d = ImageDraw.Draw(im)
d.rectangle([(0, 0), (100, 50)], fill="#f00")
d.rectangle([(0, 50), (100, 100)], fill="#0f0")
im_list.append(im)
im_list[0].save(
out, save_all=True, append_images=im_list[1:], disposal=[0, 2], background=1
)
im = Image.open(out)
im.seek(1)
self.assertEqual(im.getpixel((0, 0)), 0)
def test_iss634(self):
img = Image.open("Tests/images/iss634.gif")
# seek to the second frame
img.seek(img.tell() + 1)
# all transparent pixels should be replaced with the color from the
# first frame
self.assertEqual(img.histogram()[img.info["transparency"]], 0)
def test_duration(self):
duration = 1000
out = self.tempfile("temp.gif")
im = Image.new("L", (100, 100), "#000")
# Check that the argument has priority over the info settings
im.info["duration"] = 100
im.save(out, duration=duration)
reread = Image.open(out)
self.assertEqual(reread.info["duration"], duration)
def test_multiple_duration(self):
duration_list = [1000, 2000, 3000]
out = self.tempfile("temp.gif")
im_list = [
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#111"),
Image.new("L", (100, 100), "#222"),
]
# duration as list
im_list[0].save(
out, save_all=True, append_images=im_list[1:], duration=duration_list
)
reread = Image.open(out)
for duration in duration_list:
self.assertEqual(reread.info["duration"], duration)
try:
reread.seek(reread.tell() + 1)
except EOFError:
pass
# duration as tuple
im_list[0].save(
out, save_all=True, append_images=im_list[1:], duration=tuple(duration_list)
)
reread = Image.open(out)
for duration in duration_list:
self.assertEqual(reread.info["duration"], duration)
try:
reread.seek(reread.tell() + 1)
except EOFError:
pass
def test_identical_frames(self):
duration_list = [1000, 1500, 2000, 4000]
out = self.tempfile("temp.gif")
im_list = [
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#000"),
Image.new("L", (100, 100), "#111"),
]
# duration as list
im_list[0].save(
out, save_all=True, append_images=im_list[1:], duration=duration_list
)
reread = Image.open(out)
# Assert that the first three frames were combined
self.assertEqual(reread.n_frames, 2)
# Assert that the new duration is the total of the identical frames
self.assertEqual(reread.info["duration"], 4500)
def test_number_of_loops(self):
number_of_loops = 2
out = self.tempfile("temp.gif")
im = Image.new("L", (100, 100), "#000")
im.save(out, loop=number_of_loops)
reread = Image.open(out)
self.assertEqual(reread.info["loop"], number_of_loops)
def test_background(self):
out = self.tempfile("temp.gif")
im = Image.new("L", (100, 100), "#000")
im.info["background"] = 1
im.save(out)
reread = Image.open(out)
self.assertEqual(reread.info["background"], im.info["background"])
if HAVE_WEBP and _webp.HAVE_WEBPANIM:
im = Image.open("Tests/images/hopper.webp")
self.assertIsInstance(im.info["background"], tuple)
im.save(out)
def test_comment(self):
im = Image.open(TEST_GIF)
self.assertEqual(im.info["comment"], b"File written by Adobe Photoshop\xa8 4.0")
out = self.tempfile("temp.gif")
im = Image.new("L", (100, 100), "#000")
im.info["comment"] = b"Test comment text"
im.save(out)
reread = Image.open(out)
self.assertEqual(reread.info["comment"], im.info["comment"])
def test_comment_over_255(self):
out = self.tempfile("temp.gif")
im = Image.new("L", (100, 100), "#000")
comment = b"Test comment text"
while len(comment) < 256:
comment += comment
im.info["comment"] = comment
im.save(out)
reread = Image.open(out)
self.assertEqual(reread.info["comment"], comment)
def test_zero_comment_subblocks(self):
im = Image.open("Tests/images/hopper_zero_comment_subblocks.gif")
expected = Image.open(TEST_GIF)
self.assert_image_equal(im, expected)
def test_version(self):
out = self.tempfile("temp.gif")
def assertVersionAfterSave(im, version):
im.save(out)
reread = Image.open(out)
self.assertEqual(reread.info["version"], version)
# Test that GIF87a is used by default
im = Image.new("L", (100, 100), "#000")
assertVersionAfterSave(im, b"GIF87a")
# Test setting the version to 89a
im = Image.new("L", (100, 100), "#000")
im.info["version"] = b"89a"
assertVersionAfterSave(im, b"GIF89a")
# Test that adding a GIF89a feature changes the version
im.info["transparency"] = 1
assertVersionAfterSave(im, b"GIF89a")
# Test that a GIF87a image is also saved in that format
im = Image.open("Tests/images/test.colors.gif")
assertVersionAfterSave(im, b"GIF87a")
# Test that a GIF89a image is also saved in that format
im.info["version"] = b"GIF89a"
assertVersionAfterSave(im, b"GIF87a")
def test_append_images(self):
out = self.tempfile("temp.gif")
# Test appending single frame images
im = Image.new("RGB", (100, 100), "#f00")
ims = [Image.new("RGB", (100, 100), color) for color in ["#0f0", "#00f"]]
im.copy().save(out, save_all=True, append_images=ims)
reread = Image.open(out)
self.assertEqual(reread.n_frames, 3)
# Tests appending using a generator
def imGenerator(ims):
for im in ims:
yield im
im.save(out, save_all=True, append_images=imGenerator(ims))
reread = Image.open(out)
self.assertEqual(reread.n_frames, 3)
# Tests appending single and multiple frame images
im = Image.open("Tests/images/dispose_none.gif")
ims = [Image.open("Tests/images/dispose_prev.gif")]
im.save(out, save_all=True, append_images=ims)
reread = Image.open(out)
self.assertEqual(reread.n_frames, 10)
def test_transparent_optimize(self):
# from issue #2195, if the transparent color is incorrectly
# optimized out, gif loses transparency
# Need a palette that isn't using the 0 color, and one
# that's > 128 items where the transparent color is actually
# the top palette entry to trigger the bug.
data = bytes(bytearray(range(1, 254)))
palette = ImagePalette.ImagePalette("RGB", list(range(256)) * 3)
im = Image.new("L", (253, 1))
im.frombytes(data)
im.putpalette(palette)
out = self.tempfile("temp.gif")
im.save(out, transparency=253)
reloaded = Image.open(out)
self.assertEqual(reloaded.info["transparency"], 253)
def test_rgb_transparency(self):
out = self.tempfile("temp.gif")
# Single frame
im = Image.new("RGB", (1, 1))
im.info["transparency"] = (255, 0, 0)
self.assert_warning(UserWarning, im.save, out)
reloaded = Image.open(out)
self.assertNotIn("transparency", reloaded.info)
# Multiple frames
im = Image.new("RGB", (1, 1))
im.info["transparency"] = b""
ims = [Image.new("RGB", (1, 1))]
self.assert_warning(UserWarning, im.save, out, save_all=True, append_images=ims)
reloaded = Image.open(out)
self.assertNotIn("transparency", reloaded.info)
def test_bbox(self):
out = self.tempfile("temp.gif")
im = Image.new("RGB", (100, 100), "#fff")
ims = [Image.new("RGB", (100, 100), "#000")]
im.save(out, save_all=True, append_images=ims)
reread = Image.open(out)
self.assertEqual(reread.n_frames, 2)
def test_palette_save_L(self):
# generate an L mode image with a separate palette
im = hopper("P")
im_l = Image.frombytes("L", im.size, im.tobytes())
palette = bytes(bytearray(im.getpalette()))
out = self.tempfile("temp.gif")
im_l.save(out, palette=palette)
reloaded = Image.open(out)
self.assert_image_equal(reloaded.convert("RGB"), im.convert("RGB"))
def test_palette_save_P(self):
# pass in a different palette, then construct what the image
# would look like.
# Forcing a non-straight grayscale palette.
im = hopper("P")
palette = bytes(bytearray([255 - i // 3 for i in range(768)]))
out = self.tempfile("temp.gif")
im.save(out, palette=palette)
reloaded = Image.open(out)
im.putpalette(palette)
self.assert_image_equal(reloaded, im)
def test_palette_save_ImagePalette(self):
# pass in a different palette, as an ImagePalette.ImagePalette
# effectively the same as test_palette_save_P
im = hopper("P")
palette = ImagePalette.ImagePalette("RGB", list(range(256))[::-1] * 3)
out = self.tempfile("temp.gif")
im.save(out, palette=palette)
reloaded = Image.open(out)
im.putpalette(palette)
self.assert_image_equal(reloaded, im)
def test_save_I(self):
# Test saving something that would trigger the auto-convert to 'L'
im = hopper("I")
out = self.tempfile("temp.gif")
im.save(out)
reloaded = Image.open(out)
self.assert_image_equal(reloaded.convert("L"), im.convert("L"))
def test_getdata(self):
# test getheader/getdata against legacy values
# Create a 'P' image with holes in the palette
im = Image._wedge().resize((16, 16))
im.putpalette(ImagePalette.ImagePalette("RGB"))
im.info = {"background": 0}
passed_palette = bytes(bytearray([255 - i // 3 for i in range(768)]))
GifImagePlugin._FORCE_OPTIMIZE = True
try:
h = GifImagePlugin.getheader(im, passed_palette)
d = GifImagePlugin.getdata(im)
import pickle
# Enable to get target values on pre-refactor version
# with open('Tests/images/gif_header_data.pkl', 'wb') as f:
# pickle.dump((h, d), f, 1)
with open("Tests/images/gif_header_data.pkl", "rb") as f:
(h_target, d_target) = pickle.load(f)
self.assertEqual(h, h_target)
self.assertEqual(d, d_target)
finally:
GifImagePlugin._FORCE_OPTIMIZE = False
def test_lzw_bits(self):
# see https://github.com/python-pillow/Pillow/issues/2811
im = Image.open("Tests/images/issue_2811.gif")
self.assertEqual(im.tile[0][3][0], 11) # LZW bits
# codec error prepatch
im.load()
def test_extents(self):
im = Image.open("Tests/images/test_extents.gif")
self.assertEqual(im.size, (100, 100))
im.seek(1)
self.assertEqual(im.size, (150, 150))