From a27e676b1128c4db81843d0f8556fbc3b3d9b415 Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 19 Nov 2019 14:47:15 +0200 Subject: [PATCH 01/12] Recommend upgrading pip before Pillow, and use python -m pip --- docs/installation.rst | 52 ++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 4ccc47ae4..796ba9b38 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -46,7 +46,8 @@ Basic Installation Install Pillow with :command:`pip`:: - $ pip install Pillow + python -m pip install pip + python -m pip install Pillow Windows Installation @@ -57,7 +58,8 @@ supported Pythons in both 32 and 64-bit versions in wheel, egg, and executable installers. These binaries have all of the optional libraries included except for raqm and libimagequant:: - > pip install Pillow + python -m pip install pip + python -m pip install Pillow macOS Installation @@ -68,7 +70,8 @@ versions in the wheel format. These include support for all optional libraries except libimagequant. Raqm support requires libraqm, fribidi, and harfbuzz to be installed separately:: - $ pip install Pillow + python -m pip install pip + python -m pip install Pillow Linux Installation ^^^^^^^^^^^^^^^^^^ @@ -78,7 +81,8 @@ versions in the manylinux wheel format. These include support for all optional libraries except libimagequant. Raqm support requires libraqm, fribidi, and harfbuzz to be installed separately:: - $ pip install Pillow + python -m pip install pip + python -m pip install Pillow Most major Linux distributions, including Fedora, Debian/Ubuntu and ArchLinux also include Pillow in packages that previously contained @@ -194,7 +198,8 @@ Many of Pillow's features require external libraries: Once you have installed the prerequisites, run:: - $ pip install Pillow + python -m pip install pip + python -m pip install Pillow If the prerequisites are installed in the standard library locations for your machine (e.g. :file:`/usr` or :file:`/usr/local`), no @@ -204,7 +209,7 @@ those locations by editing :file:`setup.py` or :file:`setup.cfg`, or by adding environment variables on the command line:: - $ CFLAGS="-I/usr/pkg/include" pip install pillow + CFLAGS="-I/usr/pkg/include" python -m pip install pillow If Pillow has been previously built without the required prerequisites, it may be necessary to manually clear the pip cache or @@ -248,11 +253,11 @@ Build Options Sample usage:: - $ MAX_CONCURRENCY=1 python setup.py build_ext --enable-[feature] install + MAX_CONCURRENCY=1 python setup.py build_ext --enable-[feature] install or using pip:: - $ pip install pillow --global-option="build_ext" --global-option="--enable-[feature]" + python -m pip install pillow --global-option="build_ext" --global-option="--enable-[feature]" Building on macOS @@ -268,21 +273,22 @@ tools. The easiest way to install external libraries is via `Homebrew `_. After you install Homebrew, run:: - $ brew install libtiff libjpeg webp little-cms2 + brew install libtiff libjpeg webp little-cms2 To install libraqm on macOS use Homebrew to install its dependencies:: - $ brew install freetype harfbuzz fribidi + brew install freetype harfbuzz fribidi Then see ``depends/install_raqm_cmake.sh`` to install libraqm. Now install Pillow with:: - $ pip install Pillow + python -m pip install pip + python -m pip install Pillow or from within the uncompressed source directory:: - $ python setup.py install + python setup.py install Building on Windows ^^^^^^^^^^^^^^^^^^^ @@ -296,17 +302,17 @@ Building on FreeBSD .. Note:: Only FreeBSD 10 and 11 tested -Make sure you have Python's development libraries installed.:: +Make sure you have Python's development libraries installed:: - $ sudo pkg install python2 + sudo pkg install python2 Or for Python 3:: - $ sudo pkg install python3 + sudo pkg install python3 Prerequisites are installed on **FreeBSD 10 or 11** with:: - $ sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg harfbuzz fribidi + sudo pkg install jpeg-turbo tiff webp lcms2 freetype2 openjpeg harfbuzz fribidi Then see ``depends/install_raqm_cmake.sh`` to install libraqm. @@ -319,25 +325,25 @@ development libraries installed. In Debian or Ubuntu:: - $ sudo apt-get install python-dev python-setuptools + sudo apt-get install python-dev python-setuptools Or for Python 3:: - $ sudo apt-get install python3-dev python3-setuptools + sudo apt-get install python3-dev python3-setuptools In Fedora, the command is:: - $ sudo dnf install python-devel redhat-rpm-config + sudo dnf install python-devel redhat-rpm-config Or for Python 3:: - $ sudo dnf install python3-devel redhat-rpm-config + sudo dnf install python3-devel redhat-rpm-config .. Note:: ``redhat-rpm-config`` is required on Fedora 23, but not earlier versions. Prerequisites are installed on **Ubuntu 16.04 LTS** with:: - $ sudo apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev \ + sudo apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev \ libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk \ libharfbuzz-dev libfribidi-dev @@ -345,7 +351,7 @@ Then see ``depends/install_raqm.sh`` to install libraqm. Prerequisites are installed on recent **RedHat** **Centos** or **Fedora** with:: - $ sudo dnf install libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel \ + sudo dnf install libtiff-devel libjpeg-devel openjpeg2-devel zlib-devel \ freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel \ harfbuzz-devel fribidi-devel libraqm-devel libimagequant-devel @@ -362,7 +368,7 @@ Building on Android Basic Android support has been added for compilation within the Termux environment. The dependencies can be installed by:: - $ pkg -y install python python-dev ndk-sysroot clang make \ + pkg -y install python python-dev ndk-sysroot clang make \ libjpeg-turbo-dev This has been tested within the Termux app on ChromeOS, on x86. From f663079a13f8b963ef0eac0212f4c0c2a36c69f0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 7 Dec 2019 09:26:48 +1100 Subject: [PATCH 02/12] Removed prompts [ci skip] --- docs/installation.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index 796ba9b38..39005db8e 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -95,11 +95,11 @@ Pillow can be installed on FreeBSD via the official Ports or Packages systems: **Ports**:: - $ cd /usr/ports/graphics/py-pillow && make install clean + cd /usr/ports/graphics/py-pillow && make install clean **Packages**:: - $ pkg install py27-pillow + pkg install py27-pillow .. note:: From ce62dca3264db9b31ce251106c5170eac491e92e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Dec 2019 08:15:48 +1100 Subject: [PATCH 03/12] Aligned comments correctly --- src/PIL/BmpImagePlugin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index cdef77ced..5f88c2b75 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -322,11 +322,11 @@ def _save(im, fp, filename, bitmap_header=True): if bitmap_header: offset = 14 + header + colors * 4 fp.write( - b"BM" - + o32(offset + image) # file type (magic) - + o32(0) # file size - + o32(offset) # reserved - ) # image data offset + b"BM" # file type (magic) + + o32(offset + image) # file size + + o32(0) # reserved + + o32(offset) # image data offset + ) # bitmap info header fp.write( From 4580b156b77e490d8db4545beb7a88f9494bf718 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Dec 2019 08:37:40 +1100 Subject: [PATCH 04/12] Raise an error if BMP file size is too large when saving --- Tests/test_file_bmp.py | 7 +++++++ src/PIL/BmpImagePlugin.py | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index 76cd98aba..338f52cd7 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -41,6 +41,13 @@ class TestFileBmp(PillowTestCase): self.assertEqual(im.size, reloaded.size) self.assertEqual(reloaded.format, "BMP") + def test_save_too_large(self): + outfile = self.tempfile("temp.bmp") + with Image.new("RGB", (1, 1)) as im: + im._size = (37838, 37838) + with self.assertRaises(ValueError): + im.save(outfile) + def test_dpi(self): dpi = (72, 72) diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 5f88c2b75..85e2350c5 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -321,9 +321,12 @@ def _save(im, fp, filename, bitmap_header=True): # bitmap header if bitmap_header: offset = 14 + header + colors * 4 + file_size = offset + image + if file_size > 2 ** 32 - 1: + raise ValueError("File size is too large for the BMP format") fp.write( b"BM" # file type (magic) - + o32(offset + image) # file size + + o32(file_size) # file size + o32(0) # reserved + o32(offset) # image data offset ) From 49a5bd3602001e00f276efb333a12f25fed61258 Mon Sep 17 00:00:00 2001 From: Alexander Karpinsky Date: Sat, 21 Dec 2019 03:42:06 +0300 Subject: [PATCH 05/12] Updated CHANGES.rst [ci skip] --- CHANGES.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1ea09fff8..fe50b55e0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,9 @@ Changelog (Pillow) 7.0.0 (unreleased) ------------------ +- Fixed black lines on upscaled images with the BOX filter #4278 + [homm] + - Change default resize resampling filter from NEAREST to BICUBIC #4255 [homm] From 6a256a83965a48b90a1900e31609f7ca717f9aee Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 21 Dec 2019 13:11:12 +0200 Subject: [PATCH 06/12] make doccheck: turn warnings into errors --- docs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index 1a912039e..510c4e2cc 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -42,7 +42,7 @@ clean: -rm -rf $(BUILDDIR)/* html: - $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + $(SPHINXBUILD) -b html -W $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." From b3547dc2c0a574545604649fb8a69eb8ea37b2ba Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sat, 21 Dec 2019 13:46:38 +0200 Subject: [PATCH 07/12] --keep-going to show all of the problems Co-Authored-By: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- docs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index 510c4e2cc..ba79d9070 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -42,7 +42,7 @@ clean: -rm -rf $(BUILDDIR)/* html: - $(SPHINXBUILD) -b html -W $(ALLSPHINXOPTS) $(BUILDDIR)/html + $(SPHINXBUILD) -b html -W --keep-going $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." From 113477fbeeec718c01449dec93f40eaa66782f27 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 21 Dec 2019 14:05:50 +0200 Subject: [PATCH 08/12] Fix unexpected unindents --- src/PIL/Image.py | 2 ++ src/PIL/ImageOps.py | 1 + 2 files changed, 3 insertions(+) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index ed90a26f7..b36f64735 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2181,12 +2181,14 @@ class Image: It may also be an :py:class:`~PIL.Image.ImageTransformHandler` object:: + class Example(Image.ImageTransformHandler): def transform(size, method, data, resample, fill=1): # Return result It may also be an object with a :py:meth:`~method.getdata` method that returns a tuple supplying new **method** and **data** values:: + class Example(object): def getdata(self): method = Image.EXTENT diff --git a/src/PIL/ImageOps.py b/src/PIL/ImageOps.py index 3a6dabf5e..4391af569 100644 --- a/src/PIL/ImageOps.py +++ b/src/PIL/ImageOps.py @@ -234,6 +234,7 @@ def pad(image, size, method=Image.BICUBIC, color=None, centering=(0.5, 0.5)): :param color: The background color of the padded image. :param centering: Control the position of the original image within the padded version. + (0.5, 0.5) will keep the image centered (0, 0) will keep the image aligned to the top left (1, 1) will keep the image aligned to the bottom From d025fbe16de642d96a861653293636e4fd82f322 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sat, 21 Dec 2019 15:48:00 +0200 Subject: [PATCH 09/12] Install TkInter for Python 3, not 2 --- .travis/install.sh | 2 +- docs/installation.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis/install.sh b/.travis/install.sh index 747acb448..48bcf0016 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -3,7 +3,7 @@ set -e sudo apt-get update -sudo apt-get -qq install libfreetype6-dev liblcms2-dev python-tk\ +sudo apt-get -qq install libfreetype6-dev liblcms2-dev python3-tk\ ghostscript libffi-dev libjpeg-turbo-progs libopenjp2-7-dev\ cmake imagemagick libharfbuzz-dev libfribidi-dev diff --git a/docs/installation.rst b/docs/installation.rst index 385b570b6..a68668973 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -335,7 +335,7 @@ Or for Python 3:: Prerequisites are installed on **Ubuntu 16.04 LTS** with:: $ sudo apt-get install libtiff5-dev libjpeg8-dev libopenjp2-7-dev zlib1g-dev \ - libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk \ + libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python3-tk \ libharfbuzz-dev libfribidi-dev Then see ``depends/install_raqm.sh`` to install libraqm. From 5027b97c69692e5a86552dfd82833a584f2e4e56 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 23 Dec 2019 21:17:04 +1100 Subject: [PATCH 10/12] Use the same Python version to build docs in Travis and GHA --- .travis/install.sh | 4 ++-- .travis/test.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis/install.sh b/.travis/install.sh index 747acb448..926e38303 100755 --- a/.travis/install.sh +++ b/.travis/install.sh @@ -20,8 +20,8 @@ if [[ $TRAVIS_PYTHON_VERSION == 3.* ]]; then pip install pyqt5 fi -# docs only on Python 3.7 -if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then pip install -r requirements.txt ; fi +# docs only on Python 3.8 +if [ "$TRAVIS_PYTHON_VERSION" == "3.8" ]; then pip install -r requirements.txt ; fi # webp pushd depends && ./install_webp.sh && popd diff --git a/.travis/test.sh b/.travis/test.sh index 91dae9f8d..832d90433 100755 --- a/.travis/test.sh +++ b/.travis/test.sh @@ -5,4 +5,4 @@ set -e python -m pytest -v -x --cov PIL --cov Tests --cov-report term Tests # Docs -if [ "$TRAVIS_PYTHON_VERSION" == "3.7" ]; then make doccheck; fi +if [ "$TRAVIS_PYTHON_VERSION" == "3.8" ]; then make doccheck; fi From fbb14f67a30b612454bc7cf9a5f73d6b35e7eb14 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Mon, 23 Dec 2019 12:26:59 +0200 Subject: [PATCH 11/12] Only check docs on Travis At least whilst there's a problem on GHA: https://github.community/t5/GitHub-Actions/GitHub-Action-for-python-import-of-quot-tkinter-quot-fails/td-p/40644 --- .github/workflows/test.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78307b7a1..0a4dcc544 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,12 +83,6 @@ jobs: name: errors path: Tests/errors - - name: Docs - if: matrix.python-version == 3.8 - run: | - pip install sphinx-rtd-theme - make doccheck - - name: After success if: success() run: | From 74a80346446e366daa0342df092a02776e8121dc Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Dec 2019 14:50:53 +1100 Subject: [PATCH 12/12] Updated draft documentation [ci skip] --- src/PIL/Image.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index b36f64735..770dc3c93 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1127,15 +1127,14 @@ class Image: Configures the image file loader so it returns a version of the image that as closely as possible matches the given mode and size. For example, you can use this method to convert a color - JPEG to greyscale while loading it, or to extract a 128x192 - version from a PCD file. + JPEG to greyscale while loading it. Note that this method modifies the :py:class:`~PIL.Image.Image` object in place. If the image has already been loaded, this method has no effect. Note: This method is not implemented for most images. It is - currently implemented only for JPEG and PCD images. + currently implemented only for JPEG and MPO images. :param mode: The requested mode. :param size: The requested size.