Fixed #33079 -- Fixed get_image_dimensions() on nonexistent images.
Thanks Nick Pope for the review.
This commit is contained in:
parent
c1d50b901b
commit
d0ea01af28
|
@ -44,7 +44,10 @@ def get_image_dimensions(file_or_path, close=False):
|
||||||
file_pos = file.tell()
|
file_pos = file.tell()
|
||||||
file.seek(0)
|
file.seek(0)
|
||||||
else:
|
else:
|
||||||
file = open(file_or_path, 'rb')
|
try:
|
||||||
|
file = open(file_or_path, 'rb')
|
||||||
|
except OSError:
|
||||||
|
return (None, None)
|
||||||
close = True
|
close = True
|
||||||
try:
|
try:
|
||||||
# Most of the time Pillow only needs a small chunk to parse the image
|
# Most of the time Pillow only needs a small chunk to parse the image
|
||||||
|
|
|
@ -369,6 +369,10 @@ class GetImageDimensionsTests(unittest.TestCase):
|
||||||
size = images.get_image_dimensions(fh)
|
size = images.get_image_dimensions(fh)
|
||||||
self.assertEqual(size, (None, None))
|
self.assertEqual(size, (None, None))
|
||||||
|
|
||||||
|
def test_missing_file(self):
|
||||||
|
size = images.get_image_dimensions('missing.png')
|
||||||
|
self.assertEqual(size, (None, None))
|
||||||
|
|
||||||
@unittest.skipUnless(HAS_WEBP, 'WEBP not installed')
|
@unittest.skipUnless(HAS_WEBP, 'WEBP not installed')
|
||||||
def test_webp(self):
|
def test_webp(self):
|
||||||
img_path = os.path.join(os.path.dirname(__file__), 'test.webp')
|
img_path = os.path.join(os.path.dirname(__file__), 'test.webp')
|
||||||
|
|
Loading…
Reference in New Issue