Merge pull request #761 from wiredfool/jpeg2k_fd

Jpeg2k
This commit is contained in:
Alex Clark ☺ 2014-07-01 16:16:26 -04:00
commit 351f2ae948
2 changed files with 16 additions and 11 deletions

View File

@ -172,18 +172,16 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
fd = -1
length = -1
if hasattr(self.fp, "fileno"):
try:
fd = self.fp.fileno()
length = os.fstat(fd).st_size
except:
fd = -1
try:
fd = self.fp.fileno()
length = os.fstat(fd).st_size
except:
fd = -1
elif hasattr(self.fp, "seek"):
try:
pos = f.tell()
f.seek(0, 2)
length = f.tell()
f.seek(pos, 0)
pos = self.fp.tell()
self.fp.seek(0, 2)
length = self.fp.tell()
self.fp.seek(pos, 0)
except:
length = -1

View File

@ -39,6 +39,13 @@ class TestFileJpeg2k(PillowTestCase):
self.assertEqual(im.size, (640, 480))
self.assertEqual(im.format, 'JPEG2000')
def test_bytesio(self):
with open('Tests/images/test-card-lossless.jp2', 'rb') as f:
data = BytesIO(f.read())
im = Image.open(data)
im.load()
self.assert_image_similar(im, test_card, 1.0e-3)
# These two test pre-written JPEG 2000 files that were not written with
# PIL (they were made using Adobe Photoshop)