mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-07 05:13:15 +03:00
TIFF: report correct image size after opening
This commit is contained in:
parent
a60736381e
commit
5ca413dd38
|
@ -49,5 +49,6 @@ def test_copy_zero() -> None:
|
||||||
@skip_unless_feature("libtiff")
|
@skip_unless_feature("libtiff")
|
||||||
def test_deepcopy() -> None:
|
def test_deepcopy() -> None:
|
||||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
||||||
|
assert im.size == (590, 88)
|
||||||
out = copy.deepcopy(im)
|
out = copy.deepcopy(im)
|
||||||
assert out.size == (590, 88)
|
assert out.size == (590, 88)
|
||||||
|
|
|
@ -17,7 +17,6 @@ from .helper import (
|
||||||
assert_image_equal_tofile,
|
assert_image_equal_tofile,
|
||||||
assert_image_similar,
|
assert_image_similar,
|
||||||
hopper,
|
hopper,
|
||||||
skip_unless_feature,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -299,14 +298,6 @@ class TestImageResize:
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
im.resize((10, 10), "unknown")
|
im.resize((10, 10), "unknown")
|
||||||
|
|
||||||
@skip_unless_feature("libtiff")
|
|
||||||
def test_load_first(self) -> None:
|
|
||||||
# load() may change the size of the image
|
|
||||||
# Test that resize() is calling it before getting the size
|
|
||||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
|
||||||
im = im.resize((64, 64))
|
|
||||||
assert im.size == (64, 64)
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("mode", ("L", "RGB", "I", "F"))
|
@pytest.mark.parametrize("mode", ("L", "RGB", "I", "F"))
|
||||||
def test_default_filter_bicubic(self, mode: str) -> None:
|
def test_default_filter_bicubic(self, mode: str) -> None:
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
|
|
|
@ -9,7 +9,6 @@ from .helper import (
|
||||||
assert_image_similar,
|
assert_image_similar,
|
||||||
fromstring,
|
fromstring,
|
||||||
hopper,
|
hopper,
|
||||||
skip_unless_feature,
|
|
||||||
tostring,
|
tostring,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -90,22 +89,6 @@ def test_no_resize() -> None:
|
||||||
im.thumbnail((64, 64))
|
im.thumbnail((64, 64))
|
||||||
assert im.size == (64, 64)
|
assert im.size == (64, 64)
|
||||||
|
|
||||||
|
|
||||||
@skip_unless_feature("libtiff")
|
|
||||||
def test_load_first() -> None:
|
|
||||||
# load() may change the size of the image
|
|
||||||
# Test that thumbnail() is calling it before performing size calculations
|
|
||||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
|
||||||
im.thumbnail((64, 64))
|
|
||||||
assert im.size == (64, 10)
|
|
||||||
|
|
||||||
# Test thumbnail(), without draft(),
|
|
||||||
# on an image that is large enough once load() has changed the size
|
|
||||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
|
||||||
im.thumbnail((590, 88), reducing_gap=None)
|
|
||||||
assert im.size == (590, 88)
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_first_unless_jpeg() -> None:
|
def test_load_first_unless_jpeg() -> None:
|
||||||
# Test that thumbnail() still uses draft() for JPEG
|
# Test that thumbnail() still uses draft() for JPEG
|
||||||
with Image.open("Tests/images/hopper.jpg") as im:
|
with Image.open("Tests/images/hopper.jpg") as im:
|
||||||
|
|
|
@ -240,8 +240,9 @@ def test_zero_size() -> None:
|
||||||
@skip_unless_feature("libtiff")
|
@skip_unless_feature("libtiff")
|
||||||
def test_load_first() -> None:
|
def test_load_first() -> None:
|
||||||
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
with Image.open("Tests/images/g4_orientation_5.tif") as im:
|
||||||
|
assert im.size == (590, 88)
|
||||||
a = numpy.array(im)
|
a = numpy.array(im)
|
||||||
assert a.shape == (88, 590)
|
assert a.shape == (88, 590)
|
||||||
|
|
||||||
|
|
||||||
def test_bool() -> None:
|
def test_bool() -> None:
|
||||||
|
|
|
@ -322,8 +322,9 @@ class ImageFile(Image.Image):
|
||||||
|
|
||||||
def load_prepare(self) -> None:
|
def load_prepare(self) -> None:
|
||||||
# create image memory if necessary
|
# create image memory if necessary
|
||||||
if self._im is None or self.im.mode != self.mode or self.im.size != self.size:
|
# use internal _size property for correct tile size
|
||||||
self.im = Image.core.new(self.mode, self.size)
|
if self._im is None or self.im.mode != self.mode or self.im.size != self._size:
|
||||||
|
self.im = Image.core.new(self.mode, self._size)
|
||||||
# create palette (optional)
|
# create palette (optional)
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
Image.Image.load(self)
|
Image.Image.load(self)
|
||||||
|
|
|
@ -1275,6 +1275,13 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
return self._load_libtiff()
|
return self._load_libtiff()
|
||||||
return super().load()
|
return super().load()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def size(self) -> tuple[int, int]:
|
||||||
|
if hasattr(self, 'tag_v2'):
|
||||||
|
if self.tag_v2.get(ExifTags.Base.Orientation) in (5, 6, 7, 8):
|
||||||
|
return (self._size[1], self._size[0])
|
||||||
|
return self._size
|
||||||
|
|
||||||
def load_end(self) -> None:
|
def load_end(self) -> None:
|
||||||
# allow closing if we're on the first frame, there's no next
|
# allow closing if we're on the first frame, there's no next
|
||||||
# This is the ImageFile.load path only, libtiff specific below.
|
# This is the ImageFile.load path only, libtiff specific below.
|
||||||
|
@ -1559,7 +1566,7 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
if STRIPOFFSETS in self.tag_v2:
|
if STRIPOFFSETS in self.tag_v2:
|
||||||
offsets = self.tag_v2[STRIPOFFSETS]
|
offsets = self.tag_v2[STRIPOFFSETS]
|
||||||
h = self.tag_v2.get(ROWSPERSTRIP, ysize)
|
h = self.tag_v2.get(ROWSPERSTRIP, ysize)
|
||||||
w = self.size[0]
|
w = xsize
|
||||||
else:
|
else:
|
||||||
# tiled image
|
# tiled image
|
||||||
offsets = self.tag_v2[TILEOFFSETS]
|
offsets = self.tag_v2[TILEOFFSETS]
|
||||||
|
@ -1593,9 +1600,9 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
x = x + w
|
x = x + w
|
||||||
if x >= self.size[0]:
|
if x >= xsize:
|
||||||
x, y = 0, y + h
|
x, y = 0, y + h
|
||||||
if y >= self.size[1]:
|
if y >= ysize:
|
||||||
x = y = 0
|
x = y = 0
|
||||||
layer += 1
|
layer += 1
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user