Skip to content

Commit

Permalink
Merge branch 'main' into cover
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere authored Sep 30, 2023
2 parents 1c5eab7 + 8cb1e29 commit 955b2d5
Show file tree
Hide file tree
Showing 34 changed files with 192 additions and 117 deletions.
6 changes: 2 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ environment:
install:
- '%PYTHON%\%EXECUTABLE% --version'
- '%PYTHON%\%EXECUTABLE% -m pip install --upgrade pip'
- curl -fsSL -o pillow-depends.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
- curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
- 7z x pillow-depends.zip -oc:\
- 7z x pillow-test-images.zip -oc:\
- mv c:\pillow-depends-main c:\pillow-depends
- xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images
- 7z x ..\pillow-depends\nasm-2.16.01-win64.zip -oc:\
- curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.01-win64.zip
- 7z x nasm-win64.zip -oc:\
- choco install ghostscript --version=10.0.0.20230317
- path c:\nasm-2.16.01;C:\Program Files\gs\gs10.00.0\bin;%PATH%
- cd c:\pillow\winbuild\
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
permissions:
contents: read

concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
permissions:
issues: write

concurrency:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

Expand Down
17 changes: 14 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
- repo: https://github.com/asottile/pyupgrade
rev: v3.13.0
hooks:
- id: pyupgrade
args: [--py38-plus]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.9.1
hooks:
- id: black
args: [--target-version=py38]
Expand Down Expand Up @@ -33,7 +39,7 @@ repos:
hooks:
- id: flake8
additional_dependencies:
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat]
[flake8-2020, flake8-errmsg, flake8-implicit-str-concat, flake8-logging]

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
Expand All @@ -44,10 +50,15 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
exclude: ^Tests/images/
- id: trailing-whitespace
exclude: ^.github/.*TEMPLATE|^Tests/(fonts|images)/

- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.8
Expand Down
3 changes: 0 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ Changelog (Pillow)
- Added session type check for Linux in ImageGrab.grabclipboard() #7332
[TheNooB2706, radarhere, hugovk]

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

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

Expand Down
Empty file modified Tests/check_j2k_leaks.py
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Tests/fonts/DejaVuSans/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ The Font Software may be sold as part of a larger software package but no copy o

THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

Except as contained in this notice, the name of Tavmjong Bah shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
Except as contained in this notice, the name of Tavmjong Bah shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Font Software without prior written authorization from Tavmjong Bah. For further information, contact: tavmjong @ free . fr.
4 changes: 2 additions & 2 deletions Tests/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def assert_image_equal(a, b, msg=None):
if HAS_UPLOADER:
try:
url = test_image_results.upload(a, b)
logger.error(f"Url for test images: {url}")
logger.error("URL for test images: %s", url)
except Exception:
pass

Expand Down Expand Up @@ -126,7 +126,7 @@ def assert_image_similar(a, b, epsilon, msg=None):
if HAS_UPLOADER:
try:
url = test_image_results.upload(a, b)
logger.error(f"Url for test images: {url}")
logger.exception("URL for test images: %s", url)
except Exception:
pass
raise e
Expand Down
1 change: 0 additions & 1 deletion Tests/icc/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ and that the name of ICC shall not be used in advertising or publicity
pertaining to distribution of the software without specific, written
prior permission. ICC makes no representations about the suitability
of this software for any purpose.

Empty file modified Tests/images/negative_size.ppm
100755 → 100644
Empty file.
11 changes: 11 additions & 0 deletions Tests/test_file_webp.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,15 @@ 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

def test_roundtrip_rgba_palette(self, tmp_path):
temp_file = str(tmp_path / "temp.webp")
im = Image.new("RGBA", (1, 1)).convert("P")
assert im.mode == "P"
assert im.palette.mode == "RGBA"
im.save(temp_file)

with Image.open(temp_file) as im:
assert im.getpixel((0, 0)) == (0, 0, 0, 0)
25 changes: 25 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,31 @@ def test_zero_tobytes(self, size):
im = Image.new("RGB", size)
assert im.tobytes() == b""

def test_has_transparency_data(self):
for mode in ("1", "L", "P", "RGB"):
im = Image.new(mode, (1, 1))
assert not im.has_transparency_data

for mode in ("LA", "La", "PA", "RGBA", "RGBa"):
im = Image.new(mode, (1, 1))
assert im.has_transparency_data

# P mode with "transparency" info
with Image.open("Tests/images/first_frame_transparency.gif") as im:
assert "transparency" in im.info
assert im.has_transparency_data

# RGB mode with "transparency" info
with Image.open("Tests/images/rgb_trns.png") as im:
assert "transparency" in im.info
assert im.has_transparency_data

# P mode with RGBA palette
im = Image.new("RGBA", (1, 1)).convert("P")
assert im.mode == "P"
assert im.palette.mode == "RGBA"
assert im.has_transparency_data

def test_apply_transparency(self):
im = Image.new("P", (1, 1))
im.putpalette((0, 0, 0, 1, 1, 1))
Expand Down
Empty file modified _custom_build/backend.py
100755 → 100644
Empty file.
1 change: 0 additions & 1 deletion depends/install_raqm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ pushd $archive
meson build --prefix=/usr && sudo ninja -C build install

popd

1 change: 0 additions & 1 deletion depends/install_raqm_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ make && sudo make install
cd ..

popd

1 change: 0 additions & 1 deletion depends/termux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

pkg install -y python ndk-sysroot clang make \
libjpeg-turbo

4 changes: 3 additions & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,13 @@ These platforms have been reported to work at the versions mentioned.
| Operating system | | Tested Python | | Latest tested | | Tested |
| | | versions | | Pillow version | | processors |
+==================================+===========================+==================+==============+
| macOS 14 Sonoma | 3.8, 3.9, 3.10, 3.11 | 10.0.1 |arm |
+----------------------------------+---------------------------+------------------+--------------+
| macOS 13 Ventura | 3.8, 3.9, 3.10, 3.11 | 10.0.1 |arm |
| +---------------------------+------------------+ |
| | 3.7 | 9.5.0 | |
+----------------------------------+---------------------------+------------------+--------------+
| macOS 12 Big Sur | 3.7, 3.8, 3.9, 3.10, 3.11 | 9.3.0 |arm |
| macOS 12 Monterey | 3.7, 3.8, 3.9, 3.10, 3.11 | 9.3.0 |arm |
+----------------------------------+---------------------------+------------------+--------------+
| macOS 11 Big Sur | 3.7, 3.8, 3.9, 3.10 | 8.4.0 |arm |
| +---------------------------+------------------+--------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/newer-versions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Pillow 9.3 - 9.5,,Yes,Yes,Yes,Yes,Yes,,
Pillow 9.0 - 9.2,,,Yes,Yes,Yes,Yes,,
Pillow 8.3.2 - 8.4,,,Yes,Yes,Yes,Yes,Yes,
Pillow 8.0 - 8.3.1,,,,Yes,Yes,Yes,Yes,
Pillow 7.0 - 7.2,,,,,Yes,Yes,Yes,Yes
Pillow 7.0 - 7.2,,,,,Yes,Yes,Yes,Yes
2 changes: 1 addition & 1 deletion docs/older-versions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Pillow 5.2 - 5.4,,Yes,Yes,Yes,Yes,,,Yes,,,
Pillow 5.0 - 5.1,,,Yes,Yes,Yes,,,Yes,,,
Pillow 4,,,Yes,Yes,Yes,Yes,,Yes,,,
Pillow 2 - 3,,,,Yes,Yes,Yes,Yes,Yes,Yes,,
Pillow < 2,,,,,,,,Yes,Yes,Yes,Yes
Pillow < 2,,,,,,,,Yes,Yes,Yes,Yes
2 changes: 2 additions & 0 deletions docs/reference/Image.rst
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ Instances of the :py:class:`Image` class have the following attributes:

.. seealso:: :attr:`~Image.is_animated`, :func:`~Image.seek` and :func:`~Image.tell`

.. autoattribute:: PIL.Image.Image.has_transparency_data

Classes
-------

Expand Down
11 changes: 11 additions & 0 deletions docs/releasenotes/10.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ while maintaining the original aspect ratio.
See :ref:`relative-resize` for a comparison between this and similar ImageOps
methods.

has_transparency_data
^^^^^^^^^^^^^^^^^^^^^

Images now have :py:attr:`~PIL.Image.Image.has_transparency_data` to indicate
whether the image has transparency data, whether in the form of an alpha
channel, a palette with an alpha channel, or a "transparency" key in the
:py:attr:`~PIL.Image.Image.info` dictionary.

Even if this attribute is true, the image might still appear solid, if all of
the values shown within are opaque.

Security
========

Expand Down
1 change: 0 additions & 1 deletion docs/releasenotes/3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,3 @@ The external dependencies on libjpeg and zlib are now required by default.
If the headers or libraries are not found, then installation will abort
with an error. This behaviour can be disabled with the ``--disable-libjpeg``
and ``--disable-zlib`` flags.

4 changes: 0 additions & 4 deletions docs/releasenotes/3.3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,3 @@ image size can lead to a smaller allocation than expected, leading to
arbitrary writes.

This issue was found by Cris Neckar at Divergent Security.




2 changes: 0 additions & 2 deletions docs/releasenotes/4.1.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ CPython 3.6.1 to not work on installations of C-Python 3.6.0. This fix
undefines PySlice_GetIndicesEx if it exists to restore compatibility
with both 3.6.0 and 3.6.1. See https://bugs.python.org/issue29943 for
more details.


1 change: 0 additions & 1 deletion docs/releasenotes/4.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ Fixed Windows PyPy Build

A change in the 4.2.0 cycle broke the Windows PyPy build. This has
been fixed, and PyPy is now part of the Windows CI matrix.

3 changes: 0 additions & 3 deletions docs/releasenotes/8.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,3 @@ Dark theme for docs
^^^^^^^^^^^^^^^^^^^

The https://pillow.readthedocs.io documentation will use a dark theme if the user has requested the system use one. Uses the ``prefers-color-scheme`` CSS media query.



4 changes: 2 additions & 2 deletions src/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def bdf_char(f):
# followed by the width in x (BBw), height in y (BBh),
# and x and y displacement (BBxoff0, BByoff0)
# of the lower left corner from the origin of the character.
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())

# The word DWIDTH
# followed by the width in x and y of the character in device pixels.
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
dwx, dwy = (int(p) for p in props["DWIDTH"].split())

bbox = (
(dwx, dwy),
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def check_required_header_comments():
# data start identifier (the image data follows after a single line
# consisting only of this quoted value)
image_data_values = byte_arr[11:bytes_read].split(None, 7)
columns, rows, bit_depth, mode_id = [
columns, rows, bit_depth, mode_id = (
int(value) for value in image_data_values[:4]
]
)

if bit_depth == 1:
self._mode = "1"
Expand Down
20 changes: 19 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def convert(

self.load()

has_transparency = self.info.get("transparency") is not None
has_transparency = "transparency" in self.info
if not mode and self.mode == "P":
# determine default mode
if self.palette:
Expand Down Expand Up @@ -1531,6 +1531,24 @@ def getpalette(self, rawmode="RGB"):
rawmode = mode
return list(self.im.getpalette(mode, rawmode))

@property
def has_transparency_data(self) -> bool:
"""
Determine if an image has transparency data, whether in the form of an
alpha channel, a palette with an alpha channel, or a "transparency" key
in the info dictionary.
Note the image might still appear solid, if all of the values shown
within are opaque.
:returns: A boolean.
"""
return (
self.mode in ("LA", "La", "PA", "RGBA", "RGBa")
or (self.mode == "P" and self.palette.mode.endswith("A"))
or "transparency" in self.info
)

def apply_transparency(self):
"""
If a P mode image has a "transparency" key in the info dictionary,
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def grabclipboard():
msg = "wl-paste or xclip is required for ImageGrab.grabclipboard() on Linux"
raise NotImplementedError(msg)

p = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.run(args, capture_output=True)
err = p.stderr
if err:
msg = f"{args[0]} error: {err.strip().decode()}"
Expand Down
Loading

0 comments on commit 955b2d5

Please sign in to comment.