mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 09:14:27 +03:00
f doesn't exist, BytesIO objects have fileno(), but may return OsError
This commit is contained in:
parent
a47b8c15da
commit
cec5fd9d38
|
@ -172,18 +172,16 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
||||||
fd = -1
|
fd = -1
|
||||||
length = -1
|
length = -1
|
||||||
|
|
||||||
if hasattr(self.fp, "fileno"):
|
try:
|
||||||
|
fd = self.fp.fileno()
|
||||||
|
length = os.fstat(fd).st_size
|
||||||
|
except:
|
||||||
|
fd = -1
|
||||||
try:
|
try:
|
||||||
fd = self.fp.fileno()
|
pos = self.fp.tell()
|
||||||
length = os.fstat(fd).st_size
|
self.fp.seek(0, 2)
|
||||||
except:
|
length = self.fp.tell()
|
||||||
fd = -1
|
self.fp.seek(pos, 0)
|
||||||
elif hasattr(self.fp, "seek"):
|
|
||||||
try:
|
|
||||||
pos = f.tell()
|
|
||||||
f.seek(0, 2)
|
|
||||||
length = f.tell()
|
|
||||||
f.seek(pos, 0)
|
|
||||||
except:
|
except:
|
||||||
length = -1
|
length = -1
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,14 @@ class TestFileJpeg2k(PillowTestCase):
|
||||||
self.assertEqual(im.size, (640, 480))
|
self.assertEqual(im.size, (640, 480))
|
||||||
self.assertEqual(im.format, 'JPEG2000')
|
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()
|
||||||
|
print ("bytesio")
|
||||||
|
self.assert_image_similar(im, test_card, 1.0e-3)
|
||||||
|
|
||||||
# These two test pre-written JPEG 2000 files that were not written with
|
# These two test pre-written JPEG 2000 files that were not written with
|
||||||
# PIL (they were made using Adobe Photoshop)
|
# PIL (they were made using Adobe Photoshop)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user