From d29d35812414ecd1c27302777d57725f57c2e4a9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 18 Jan 2017 20:04:01 +1100 Subject: [PATCH 1/3] Removed duplicate code --- PIL/GdImageFile.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/PIL/GdImageFile.py b/PIL/GdImageFile.py index 09ab5ec6964..5b7dc3d7683 100644 --- a/PIL/GdImageFile.py +++ b/PIL/GdImageFile.py @@ -25,16 +25,9 @@ from . import ImageFile, ImagePalette from ._binary import i16be as i16 -from ._util import isPath __version__ = "0.1" -try: - import builtins -except ImportError: - import __builtin__ - builtins = __builtin__ - ## # Image plugin for the GD uncompressed format. Note that this format @@ -78,13 +71,7 @@ def open(fp, mode="r"): if mode != "r": raise ValueError("bad mode") - if isPath(fp): - filename = fp - fp = builtins.open(fp, "rb") - else: - filename = "" - try: - return GdImageFile(fp, filename) + return GdImageFile(fp) except SyntaxError: raise IOError("cannot identify this image file") From 1f5c049bd4ef43c22192074c336acc6d43e401a2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 7 Oct 2016 23:59:26 +1100 Subject: [PATCH 2/3] Corrected info key --- PIL/GdImageFile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/GdImageFile.py b/PIL/GdImageFile.py index 5b7dc3d7683..645aae6e348 100644 --- a/PIL/GdImageFile.py +++ b/PIL/GdImageFile.py @@ -51,7 +51,7 @@ def _open(self): # transparency index tindex = i16(s[5:7]) if tindex < 256: - self.info["transparent"] = tindex + self.info["transparency"] = tindex self.palette = ImagePalette.raw("RGB", s[7:]) From b6342392718f05f19d567005b4121d2e422b6f2e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 8 Oct 2016 00:09:21 +1100 Subject: [PATCH 3/3] Added GD tests --- PIL/GdImageFile.py | 2 +- Tests/images/gd | Bin 0 -> 1237 bytes Tests/test_file_gd.py | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Tests/images/gd create mode 100644 Tests/test_file_gd.py diff --git a/PIL/GdImageFile.py b/PIL/GdImageFile.py index 645aae6e348..8747a89c231 100644 --- a/PIL/GdImageFile.py +++ b/PIL/GdImageFile.py @@ -46,7 +46,7 @@ def _open(self): s = self.fp.read(775) self.mode = "L" # FIXME: "P" - self.size = i16(s[0:2]), i16(s[2:4]) + self.size = i16(s[2:4]), i16(s[4:6]) # transparency index tindex = i16(s[5:7]) diff --git a/Tests/images/gd b/Tests/images/gd new file mode 100644 index 0000000000000000000000000000000000000000..ccc848be6292f49a9093cbe41b6149f7fbcde245 GIT binary patch literal 1237 jcmezWpMi@(gn@zaKM=4mu`rB+(GVC7fzc2c${_#%fxHGJ literal 0 HcmV?d00001 diff --git a/Tests/test_file_gd.py b/Tests/test_file_gd.py new file mode 100644 index 00000000000..fe6f7e36b2c --- /dev/null +++ b/Tests/test_file_gd.py @@ -0,0 +1,17 @@ +from helper import unittest, PillowTestCase + +from PIL import GdImageFile + +TEST_GD_FILE = "Tests/images/gd" + + +class TestFileGd(PillowTestCase): + + def test_sanity(self): + im = GdImageFile.open(TEST_GD_FILE) + self.assertEqual(im.size, (10, 20)) + self.assertEqual(im.format, "GD") + + +if __name__ == '__main__': + unittest.main()