Skip to content

Commit

Permalink
Merge branch 'main' into iptc
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 22, 2023
2 parents b37ca35 + 52206c7 commit dcfce94
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 154 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
args: [--target-version=py38]
Expand All @@ -23,13 +23,13 @@ repos:
- id: yesqa

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.3
hooks:
- id: remove-tabs
exclude: (Makefile$|\.bat$|\.cmake$|\.eps$|\.fits$|\.gd$|\.opt$)

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
Expand All @@ -55,7 +55,7 @@ repos:
- id: sphinx-lint

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.12.1
rev: 0.13.0
hooks:
- id: pyproject-fmt

Expand Down
15 changes: 15 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ Changelog (Pillow)
10.1.0 (unreleased)
-------------------

- Read WebP duration after opening #7311
[k128, radarhere]

- Allow "loop=None" when saving GIF images #7329
[radarhere]

- Fixed transparency when saving P mode images to PDF #7323
[radarhere]

- Added saving LA images as PDFs #7299
[radarhere]

- Set SMaskInData to 1 for PDFs with alpha #7316, #7317
[radarhere]

- Changed Image mode property to be read-only by default #7307
[radarhere]

Expand Down
8 changes: 8 additions & 0 deletions Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ def test_identical_frames_to_single_frame(duration, tmp_path):
assert reread.info["duration"] == 8500


def test_loop_none(tmp_path):
out = str(tmp_path / "temp.gif")
im = Image.new("L", (100, 100), "#000")
im.save(out, loop=None)
with Image.open(out) as reread:
assert "loop" not in reread.info


def test_number_of_loops(tmp_path):
number_of_loops = 2

Expand Down
16 changes: 16 additions & 0 deletions Tests/test_file_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ def test_save_alpha(tmp_path, mode):
helper_save_as_pdf(tmp_path, mode)


def test_p_alpha(tmp_path):
# Arrange
outfile = str(tmp_path / "temp.pdf")
with Image.open("Tests/images/pil123p.png") as im:
assert im.mode == "P"
assert isinstance(im.info["transparency"], bytes)

# Act
im.save(outfile)

# Assert
with open(outfile, "rb") as fp:
contents = fp.read()
assert b"\n/SMask " in contents


def test_monochrome(tmp_path):
# Arrange
mode = "1"
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_chunks(self, filename):

def test_sanity(self, tmp_path):
# internal version number
assert re.search(r"\d+\.\d+\.\d+(\.\d+)?$", features.version_codec("zlib"))
assert re.search(r"\d+(\.\d+){1,3}$", features.version_codec("zlib"))

test_file = str(tmp_path / "temp.png")

Expand Down
1 change: 0 additions & 1 deletion Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,4 @@ def test_duration(self, tmp_path):
im.save(out_webp, save_all=True)

with Image.open(out_webp) as reloaded:
reloaded.load()
assert reloaded.info["duration"] == 1000
14 changes: 7 additions & 7 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,15 +661,15 @@ def test__new(self):
blank_p.palette = None
blank_pa.palette = None

def _make_new(base_image, im, palette_result=None):
new_im = base_image._new(im)
assert new_im.mode == im.mode
assert new_im.size == im.size
assert new_im.info == base_image.info
def _make_new(base_image, image, palette_result=None):
new_image = base_image._new(image.im)
assert new_image.mode == image.mode
assert new_image.size == image.size
assert new_image.info == base_image.info
if palette_result is not None:
assert new_im.palette.tobytes() == palette_result.tobytes()
assert new_image.palette.tobytes() == palette_result.tobytes()
else:
assert new_im.palette is None
assert new_image.palette is None

_make_new(im, im_p, ImagePalette.ImagePalette(list(range(256)) * 3))
_make_new(im_p, im, None)
Expand Down
2 changes: 1 addition & 1 deletion docs/handbook/image-file-formats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ their :py:attr:`~PIL.Image.Image.info` values.

**loop**
Integer number of times the GIF should loop. 0 means that it will loop
forever. By default, the image will not loop.
forever. If omitted or ``None``, the image will not loop.

**comment**
A comment about the image.
Expand Down
7 changes: 3 additions & 4 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ Install Pillow with :command:`pip`::
.. tab:: Windows

We provide Pillow binaries for Windows compiled for the matrix of
supported Pythons in both 32 and 64-bit versions in the wheel format.
These binaries include support for all optional libraries except
libimagequant and libxcb. Raqm support requires
FriBiDi to be installed separately::
supported Pythons in 64-bit versions in the wheel format. These binaries include
support for all optional libraries except libimagequant and libxcb. Raqm support
requires FriBiDi to be installed separately::

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
Expand Down
2 changes: 1 addition & 1 deletion docs/releasenotes/10.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ Support reading signed 8-bit TIFF images
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TIFF images with signed integer data, 8 bits per sample and a photometric
interpretaton of BlackIsZero can now be read.
interpretation of BlackIsZero can now be read.
4 changes: 2 additions & 2 deletions src/PIL/GifImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def _get_global_header(im, info):
info
and (
"transparency" in info
or "loop" in info
or info.get("loop") is not None
or info.get("duration")
or info.get("comment")
)
Expand All @@ -937,7 +937,7 @@ def _get_global_header(im, info):
# Global Color Table
_get_header_palette(palette_bytes),
]
if "loop" in info:
if info.get("loop") is not None:
header.append(
b"!"
+ o8(255) # extension intro
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageMath.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def eval(expression, _dict={}, **kw):

def scan(code):
for const in code.co_consts:
if type(const) == type(compiled_code):
if type(const) is type(compiled_code):
scan(const)

for name in code.co_names:
Expand Down
Loading

0 comments on commit dcfce94

Please sign in to comment.