mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #7661 from radarhere/iptc
This commit is contained in:
commit
da61ed1330
|
@ -11,6 +11,15 @@ from .helper import hopper
|
||||||
TEST_FILE = "Tests/images/iptc.jpg"
|
TEST_FILE = "Tests/images/iptc.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
def test_open():
|
||||||
|
f = BytesIO(
|
||||||
|
b"\x1c\x03<\x00\x02\x01\x00\x1c\x03x\x00\x01\x01\x1c"
|
||||||
|
b"\x03\x14\x00\x01\x01\x1c\x03\x1e\x00\x01\x01\x1c\x08\n\x00\x00"
|
||||||
|
)
|
||||||
|
with Image.open(f) as im:
|
||||||
|
assert im.tile == [("iptc", (0, 0, 1, 1), 25, "raw")]
|
||||||
|
|
||||||
|
|
||||||
def test_getiptcinfo_jpg_none():
|
def test_getiptcinfo_jpg_none():
|
||||||
# Arrange
|
# Arrange
|
||||||
with hopper() as im:
|
with hopper() as im:
|
||||||
|
|
|
@ -131,24 +131,20 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
|
|
||||||
# tile
|
# tile
|
||||||
if tag == (8, 10):
|
if tag == (8, 10):
|
||||||
self.tile = [
|
self.tile = [("iptc", (0, 0) + self.size, offset, compression)]
|
||||||
("iptc", (compression, offset), (0, 0, self.size[0], self.size[1]))
|
|
||||||
]
|
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
if len(self.tile) != 1 or self.tile[0][0] != "iptc":
|
if len(self.tile) != 1 or self.tile[0][0] != "iptc":
|
||||||
return ImageFile.ImageFile.load(self)
|
return ImageFile.ImageFile.load(self)
|
||||||
|
|
||||||
type, tile, box = self.tile[0]
|
offset, compression = self.tile[0][2:]
|
||||||
|
|
||||||
encoding, offset = tile
|
|
||||||
|
|
||||||
self.fp.seek(offset)
|
self.fp.seek(offset)
|
||||||
|
|
||||||
# Copy image data to temporary file
|
# Copy image data to temporary file
|
||||||
o_fd, outfile = tempfile.mkstemp(text=False)
|
o_fd, outfile = tempfile.mkstemp(text=False)
|
||||||
o = os.fdopen(o_fd)
|
o = os.fdopen(o_fd)
|
||||||
if encoding == "raw":
|
if compression == "raw":
|
||||||
# To simplify access to the extracted file,
|
# To simplify access to the extracted file,
|
||||||
# prepend a PPM header
|
# prepend a PPM header
|
||||||
o.write("P5\n%d %d\n255\n" % self.size)
|
o.write("P5\n%d %d\n255\n" % self.size)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user