2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2014-01-12 00:30:09 +04:00
|
|
|
import io
|
2024-01-31 12:12:58 +03:00
|
|
|
from pathlib import Path
|
2021-04-01 17:41:46 +03:00
|
|
|
|
2020-02-22 16:06:21 +03:00
|
|
|
import pytest
|
2020-08-07 13:28:33 +03:00
|
|
|
|
2023-12-27 09:42:17 +03:00
|
|
|
from PIL import EpsImagePlugin, Image, UnidentifiedImageError, features
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2021-02-21 14:22:29 +03:00
|
|
|
from .helper import (
|
|
|
|
assert_image_similar,
|
|
|
|
assert_image_similar_tofile,
|
|
|
|
hopper,
|
2023-09-12 12:46:46 +03:00
|
|
|
is_win32,
|
2021-04-10 00:33:21 +03:00
|
|
|
mark_if_feature_version,
|
2021-04-10 17:58:01 +03:00
|
|
|
skip_unless_feature,
|
2021-02-21 14:22:29 +03:00
|
|
|
)
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2018-12-30 12:50:09 +03:00
|
|
|
HAS_GHOSTSCRIPT = EpsImagePlugin.has_ghostscript()
|
|
|
|
|
2014-05-08 12:43:04 +04:00
|
|
|
# Our two EPS test files (they are identical except for their bounding boxes)
|
2020-02-23 00:03:01 +03:00
|
|
|
FILE1 = "Tests/images/zero_bb.eps"
|
|
|
|
FILE2 = "Tests/images/non_zero_bb.eps"
|
2013-11-20 10:43:10 +04:00
|
|
|
|
2014-05-08 12:43:04 +04:00
|
|
|
# Due to palletization, we'll need to convert these to RGB after load
|
2020-02-23 00:03:01 +03:00
|
|
|
FILE1_COMPARE = "Tests/images/zero_bb.png"
|
|
|
|
FILE1_COMPARE_SCALE2 = "Tests/images/zero_bb_scale2.png"
|
2013-11-20 10:43:10 +04:00
|
|
|
|
2020-02-23 00:03:01 +03:00
|
|
|
FILE2_COMPARE = "Tests/images/non_zero_bb.png"
|
|
|
|
FILE2_COMPARE_SCALE2 = "Tests/images/non_zero_bb_scale2.png"
|
2013-11-20 10:43:10 +04:00
|
|
|
|
2014-05-15 01:14:55 +04:00
|
|
|
# EPS test files with binary preview
|
2020-02-23 00:03:01 +03:00
|
|
|
FILE3 = "Tests/images/binary_preview_map.eps"
|
|
|
|
|
2023-01-12 17:36:17 +03:00
|
|
|
# Three unsigned 32bit little-endian values:
|
|
|
|
# 0xC6D3D0C5 magic number
|
|
|
|
# byte position of start of postscript section (12)
|
|
|
|
# byte length of postscript section (0)
|
|
|
|
# this byte length isn't valid, but we don't read it
|
|
|
|
simple_binary_header = b"\xc5\xd0\xd3\xc6\x0c\x00\x00\x00\x00\x00\x00\x00"
|
|
|
|
|
|
|
|
# taken from page 8 of the specification
|
|
|
|
# https://web.archive.org/web/20220120164601/https://www.adobe.com/content/dam/acom/en/devnet/actionscript/articles/5002.EPSF_Spec.pdf
|
|
|
|
simple_eps_file = (
|
|
|
|
b"%!PS-Adobe-3.0 EPSF-3.0",
|
|
|
|
b"%%BoundingBox: 5 5 105 105",
|
|
|
|
b"10 setlinewidth",
|
|
|
|
b"10 10 moveto",
|
|
|
|
b"0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath",
|
|
|
|
b"stroke",
|
|
|
|
)
|
|
|
|
simple_eps_file_with_comments = (
|
|
|
|
simple_eps_file[:1]
|
|
|
|
+ (
|
|
|
|
b"%%Comment1: Some Value",
|
|
|
|
b"%%SecondComment: Another Value",
|
|
|
|
)
|
|
|
|
+ simple_eps_file[1:]
|
|
|
|
)
|
|
|
|
simple_eps_file_without_version = simple_eps_file[1:]
|
|
|
|
simple_eps_file_without_boundingbox = simple_eps_file[:1] + simple_eps_file[2:]
|
2023-01-16 00:56:25 +03:00
|
|
|
simple_eps_file_with_invalid_boundingbox = (
|
2023-01-28 23:22:05 +03:00
|
|
|
simple_eps_file[:1] + (b"%%BoundingBox: a b c d",) + simple_eps_file[2:]
|
|
|
|
)
|
|
|
|
simple_eps_file_with_invalid_boundingbox_valid_imagedata = (
|
|
|
|
simple_eps_file_with_invalid_boundingbox + (b"%ImageData: 100 100 8 3",)
|
2023-01-16 00:56:25 +03:00
|
|
|
)
|
|
|
|
simple_eps_file_with_long_ascii_comment = (
|
|
|
|
simple_eps_file[:2] + (b"%%Comment: " + b"X" * 300,) + simple_eps_file[2:]
|
|
|
|
)
|
|
|
|
simple_eps_file_with_long_binary_data = (
|
|
|
|
simple_eps_file[:2]
|
|
|
|
+ (
|
|
|
|
b"%%BeginBinary: 300",
|
|
|
|
b"\0" * 300,
|
|
|
|
b"%%EndBinary",
|
|
|
|
)
|
|
|
|
+ simple_eps_file[2:]
|
|
|
|
)
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
2023-01-12 17:36:17 +03:00
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-08-07 12:17:49 +03:00
|
|
|
@pytest.mark.parametrize("filename, size", ((FILE1, (460, 352)), (FILE2, (360, 252))))
|
2023-01-12 17:36:17 +03:00
|
|
|
@pytest.mark.parametrize("scale", (1, 2))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_sanity(filename: str, size: tuple[int, int], scale: int) -> None:
|
2023-01-12 17:36:17 +03:00
|
|
|
expected_size = tuple(s * scale for s in size)
|
|
|
|
with Image.open(filename) as image:
|
|
|
|
image.load(scale=scale)
|
|
|
|
assert image.mode == "RGB"
|
|
|
|
assert image.size == expected_size
|
|
|
|
assert image.format == "EPS"
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
2022-02-02 03:49:31 +03:00
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_load() -> None:
|
2022-02-02 03:49:31 +03:00
|
|
|
with Image.open(FILE1) as im:
|
|
|
|
assert im.load()[0, 0] == (255, 255, 255)
|
|
|
|
|
|
|
|
# Test again now that it has already been loaded once
|
|
|
|
assert im.load()[0, 0] == (255, 255, 255)
|
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_binary() -> None:
|
2023-09-12 12:46:46 +03:00
|
|
|
if HAS_GHOSTSCRIPT:
|
|
|
|
assert EpsImagePlugin.gs_binary is not None
|
|
|
|
else:
|
|
|
|
assert EpsImagePlugin.gs_binary is False
|
|
|
|
|
|
|
|
if not is_win32():
|
|
|
|
assert EpsImagePlugin.gs_windows_binary is None
|
|
|
|
elif not HAS_GHOSTSCRIPT:
|
|
|
|
assert EpsImagePlugin.gs_windows_binary is False
|
|
|
|
else:
|
|
|
|
assert EpsImagePlugin.gs_windows_binary is not None
|
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_invalid_file() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
invalid_file = "Tests/images/flower.jpg"
|
|
|
|
with pytest.raises(SyntaxError):
|
|
|
|
EpsImagePlugin.EpsImageFile(invalid_file)
|
|
|
|
|
2021-01-07 16:57:49 +03:00
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_binary_header_only() -> None:
|
2023-01-12 17:36:17 +03:00
|
|
|
data = io.BytesIO(simple_binary_header)
|
|
|
|
with pytest.raises(SyntaxError, match='EPS header missing "%!PS-Adobe" comment'):
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_missing_version_comment(prefix: bytes) -> None:
|
2023-01-12 17:36:17 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_without_version))
|
|
|
|
with pytest.raises(SyntaxError):
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_missing_boundingbox_comment(prefix: bytes) -> None:
|
2023-01-12 17:36:17 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_without_boundingbox))
|
|
|
|
with pytest.raises(SyntaxError, match='EPS header missing "%%BoundingBox" comment'):
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
2023-01-16 00:29:23 +03:00
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_invalid_boundingbox_comment(prefix: bytes) -> None:
|
2023-01-16 00:29:23 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox))
|
|
|
|
with pytest.raises(OSError, match="cannot determine EPS bounding box"):
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
2023-01-28 23:22:05 +03:00
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_invalid_boundingbox_comment_valid_imagedata_comment(prefix: bytes) -> None:
|
2023-01-28 23:22:05 +03:00
|
|
|
data = io.BytesIO(
|
|
|
|
prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox_valid_imagedata)
|
|
|
|
)
|
|
|
|
with Image.open(data) as img:
|
|
|
|
assert img.mode == "RGB"
|
|
|
|
assert img.size == (100, 100)
|
|
|
|
assert img.format == "EPS"
|
|
|
|
|
|
|
|
|
2023-01-16 00:56:25 +03:00
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_ascii_comment_too_long(prefix: bytes) -> None:
|
2023-01-16 00:56:25 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_ascii_comment))
|
|
|
|
with pytest.raises(SyntaxError, match="not an EPS file"):
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_long_binary_data(prefix: bytes) -> None:
|
2023-01-16 00:56:25 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_binary_data))
|
|
|
|
EpsImagePlugin.EpsImageFile(data)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_load_long_binary_data(prefix: bytes) -> None:
|
2023-01-16 00:56:25 +03:00
|
|
|
data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_binary_data))
|
|
|
|
with Image.open(data) as img:
|
|
|
|
img.load()
|
|
|
|
assert img.mode == "RGB"
|
|
|
|
assert img.size == (100, 100)
|
|
|
|
assert img.format == "EPS"
|
|
|
|
|
|
|
|
|
2021-04-10 17:58:01 +03:00
|
|
|
@mark_if_feature_version(
|
|
|
|
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
|
|
|
|
)
|
2020-02-23 00:03:01 +03:00
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_cmyk() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
with Image.open("Tests/images/pil_sample_cmyk.eps") as cmyk_image:
|
|
|
|
assert cmyk_image.mode == "CMYK"
|
|
|
|
assert cmyk_image.size == (100, 100)
|
|
|
|
assert cmyk_image.format == "EPS"
|
|
|
|
|
|
|
|
cmyk_image.load()
|
|
|
|
assert cmyk_image.mode == "RGB"
|
|
|
|
|
|
|
|
if features.check("jpg"):
|
2021-02-21 14:22:29 +03:00
|
|
|
assert_image_similar_tofile(
|
|
|
|
cmyk_image, "Tests/images/pil_sample_rgb.jpg", 10
|
|
|
|
)
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_showpage() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# See https://github.com/python-pillow/Pillow/issues/2615
|
|
|
|
with Image.open("Tests/images/reqd_showpage.eps") as plot_image:
|
|
|
|
with Image.open("Tests/images/reqd_showpage.png") as target:
|
|
|
|
# should not crash/hang
|
|
|
|
plot_image.load()
|
2023-01-12 17:36:17 +03:00
|
|
|
# fonts could be slightly different
|
2020-02-23 00:03:01 +03:00
|
|
|
assert_image_similar(plot_image, target, 6)
|
|
|
|
|
|
|
|
|
2021-07-19 02:08:45 +03:00
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_transparency() -> None:
|
2021-07-19 02:08:45 +03:00
|
|
|
with Image.open("Tests/images/reqd_showpage.eps") as plot_image:
|
|
|
|
plot_image.load(transparency=True)
|
|
|
|
assert plot_image.mode == "RGBA"
|
|
|
|
|
|
|
|
with Image.open("Tests/images/reqd_showpage_transparency.png") as target:
|
2023-01-12 17:36:17 +03:00
|
|
|
# fonts could be slightly different
|
2021-07-19 02:08:45 +03:00
|
|
|
assert_image_similar(plot_image, target, 6)
|
|
|
|
|
|
|
|
|
2020-02-23 00:03:01 +03:00
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_file_object(tmp_path: Path) -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# issue 479
|
|
|
|
with Image.open(FILE1) as image1:
|
|
|
|
with open(str(tmp_path / "temp.eps"), "wb") as fh:
|
|
|
|
image1.save(fh, "EPS")
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_bytesio_object() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
with open(FILE1, "rb") as f:
|
|
|
|
img_bytes = io.BytesIO(f.read())
|
|
|
|
|
|
|
|
with Image.open(img_bytes) as img:
|
|
|
|
img.load()
|
|
|
|
|
|
|
|
with Image.open(FILE1_COMPARE) as image1_scale1_compare:
|
|
|
|
image1_scale1_compare = image1_scale1_compare.convert("RGB")
|
|
|
|
image1_scale1_compare.load()
|
|
|
|
assert_image_similar(img, image1_scale1_compare, 5)
|
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_1_mode() -> None:
|
2022-08-13 11:32:29 +03:00
|
|
|
with Image.open("Tests/images/1.eps") as im:
|
|
|
|
assert im.mode == "1"
|
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_image_mode_not_supported(tmp_path: Path) -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
im = hopper("RGBA")
|
|
|
|
tmpfile = str(tmp_path / "temp.eps")
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.save(tmpfile)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
|
|
|
@skip_unless_feature("zlib")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_render_scale1() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# We need png support for these render test
|
|
|
|
|
|
|
|
# Zero bounding box
|
|
|
|
with Image.open(FILE1) as image1_scale1:
|
|
|
|
image1_scale1.load()
|
|
|
|
with Image.open(FILE1_COMPARE) as image1_scale1_compare:
|
|
|
|
image1_scale1_compare = image1_scale1_compare.convert("RGB")
|
|
|
|
image1_scale1_compare.load()
|
|
|
|
assert_image_similar(image1_scale1, image1_scale1_compare, 5)
|
|
|
|
|
2024-01-06 04:07:55 +03:00
|
|
|
# Non-zero bounding box
|
2020-02-23 00:03:01 +03:00
|
|
|
with Image.open(FILE2) as image2_scale1:
|
|
|
|
image2_scale1.load()
|
|
|
|
with Image.open(FILE2_COMPARE) as image2_scale1_compare:
|
|
|
|
image2_scale1_compare = image2_scale1_compare.convert("RGB")
|
|
|
|
image2_scale1_compare.load()
|
|
|
|
assert_image_similar(image2_scale1, image2_scale1_compare, 10)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
|
|
|
@skip_unless_feature("zlib")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_render_scale2() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# We need png support for these render test
|
|
|
|
|
|
|
|
# Zero bounding box
|
|
|
|
with Image.open(FILE1) as image1_scale2:
|
|
|
|
image1_scale2.load(scale=2)
|
|
|
|
with Image.open(FILE1_COMPARE_SCALE2) as image1_scale2_compare:
|
|
|
|
image1_scale2_compare = image1_scale2_compare.convert("RGB")
|
|
|
|
image1_scale2_compare.load()
|
|
|
|
assert_image_similar(image1_scale2, image1_scale2_compare, 5)
|
|
|
|
|
2024-01-06 04:07:55 +03:00
|
|
|
# Non-zero bounding box
|
2020-02-23 00:03:01 +03:00
|
|
|
with Image.open(FILE2) as image2_scale2:
|
|
|
|
image2_scale2.load(scale=2)
|
|
|
|
with Image.open(FILE2_COMPARE_SCALE2) as image2_scale2_compare:
|
|
|
|
image2_scale2_compare = image2_scale2_compare.convert("RGB")
|
|
|
|
image2_scale2_compare.load()
|
|
|
|
assert_image_similar(image2_scale2, image2_scale2_compare, 10)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2022-10-03 08:57:42 +03:00
|
|
|
@pytest.mark.parametrize("filename", (FILE1, FILE2, "Tests/images/illu10_preview.eps"))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_resize(filename: str) -> None:
|
2022-10-03 08:57:42 +03:00
|
|
|
with Image.open(filename) as im:
|
|
|
|
new_size = (100, 100)
|
|
|
|
im = im.resize(new_size)
|
|
|
|
assert im.size == new_size
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2022-10-03 08:57:42 +03:00
|
|
|
@pytest.mark.parametrize("filename", (FILE1, FILE2))
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_thumbnail(filename: str) -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# Issue #619
|
2022-10-03 08:57:42 +03:00
|
|
|
with Image.open(filename) as im:
|
|
|
|
new_size = (100, 100)
|
|
|
|
im.thumbnail(new_size)
|
|
|
|
assert max(im.size) == max(new_size)
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_read_binary_preview() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# Issue 302
|
|
|
|
# open image with binary preview
|
|
|
|
with Image.open(FILE3):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2023-01-12 17:36:17 +03:00
|
|
|
@pytest.mark.parametrize("prefix", (b"", simple_binary_header))
|
2023-01-10 09:03:07 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"line_ending",
|
|
|
|
(b"\r\n", b"\n", b"\n\r", b"\r"),
|
|
|
|
)
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_readline(prefix: bytes, line_ending: bytes) -> None:
|
2023-01-12 17:36:17 +03:00
|
|
|
simple_file = prefix + line_ending.join(simple_eps_file_with_comments)
|
2023-01-10 09:03:07 +03:00
|
|
|
data = io.BytesIO(simple_file)
|
|
|
|
test_file = EpsImagePlugin.EpsImageFile(data)
|
|
|
|
assert test_file.info["Comment1"] == "Some Value"
|
|
|
|
assert test_file.info["SecondComment"] == "Another Value"
|
|
|
|
assert test_file.size == (100, 100)
|
|
|
|
|
|
|
|
|
2022-10-03 08:57:42 +03:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"filename",
|
|
|
|
(
|
2020-02-23 00:03:01 +03:00
|
|
|
"Tests/images/illu10_no_preview.eps",
|
|
|
|
"Tests/images/illu10_preview.eps",
|
|
|
|
"Tests/images/illuCS6_no_preview.eps",
|
|
|
|
"Tests/images/illuCS6_preview.eps",
|
2022-10-03 08:57:42 +03:00
|
|
|
),
|
|
|
|
)
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_open_eps(filename: str) -> None:
|
2022-10-03 08:57:42 +03:00
|
|
|
# https://github.com/python-pillow/Pillow/issues/1104
|
|
|
|
with Image.open(filename) as img:
|
|
|
|
assert img.mode == "RGB"
|
2020-02-23 00:03:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skipif(not HAS_GHOSTSCRIPT, reason="Ghostscript not available")
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_emptyline() -> None:
|
2020-02-23 00:03:01 +03:00
|
|
|
# Test file includes an empty line in the header data
|
|
|
|
emptyline_file = "Tests/images/zero_bb_emptyline.eps"
|
|
|
|
|
|
|
|
with Image.open(emptyline_file) as image:
|
|
|
|
image.load()
|
|
|
|
assert image.mode == "RGB"
|
|
|
|
assert image.size == (460, 352)
|
|
|
|
assert image.format == "EPS"
|
2021-03-08 22:31:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.timeout(timeout=5)
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
"test_file",
|
2021-04-01 17:41:46 +03:00
|
|
|
["Tests/images/timeout-d675703545fee17acab56e5fec644c19979175de.eps"],
|
2021-03-08 22:31:41 +03:00
|
|
|
)
|
2024-02-07 11:16:28 +03:00
|
|
|
def test_timeout(test_file: str) -> None:
|
2021-03-08 22:31:41 +03:00
|
|
|
with open(test_file, "rb") as f:
|
2023-12-27 09:42:17 +03:00
|
|
|
with pytest.raises(UnidentifiedImageError):
|
2021-03-08 22:31:41 +03:00
|
|
|
with Image.open(f):
|
|
|
|
pass
|
2023-09-07 21:20:35 +03:00
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_bounding_box_in_trailer() -> None:
|
2023-09-22 11:26:41 +03:00
|
|
|
# Check bounding boxes are parsed in the same way
|
|
|
|
# when specified in the header and the trailer
|
2024-07-03 09:44:45 +03:00
|
|
|
with (
|
|
|
|
Image.open("Tests/images/zero_bb_trailer.eps") as trailer_image,
|
|
|
|
Image.open(FILE1) as header_image,
|
|
|
|
):
|
2023-09-07 21:20:35 +03:00
|
|
|
assert trailer_image.size == header_image.size
|
2023-09-22 11:26:41 +03:00
|
|
|
|
|
|
|
|
2024-01-31 12:12:58 +03:00
|
|
|
def test_eof_before_bounding_box() -> None:
|
2023-09-22 11:26:41 +03:00
|
|
|
with pytest.raises(OSError):
|
|
|
|
with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"):
|
|
|
|
pass
|
2024-01-25 12:20:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_data_after_eof() -> None:
|
|
|
|
with open("Tests/images/illuCS6_preview.eps", "rb") as f:
|
|
|
|
img_bytes = io.BytesIO(f.read() + b"\r\n%" + (b" " * 255))
|
|
|
|
|
|
|
|
with Image.open(img_bytes) as img:
|
|
|
|
assert img.mode == "RGB"
|