Skip to content

Image.BOX resampling skips input pixels #9961

Description

@mzient

What did you do?

I resized an image of size 5x19 down to 5x10 with resample=Image.BOX.
The input, upscaled 10x for clarity
Image

What did you expect to happen?

I expected each input pixel to correspond to one output pixel, as per documentation.

What actually happened?

The middle row didn't contribute to the output at all - it was totally left out (see result).
Image

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04, Linux 6.8.0-138-generic
  • Python: 3.10.12
  • Pillow: 9.0.1 and 12.3.0 (tested on both, same result)
--------------------------------------------------------------------
Pillow 12.3.0
Python 3.10.12 (main, Jul 15 2026, 23:40:17) [GCC 11.4.0]
--------------------------------------------------------------------
Python executable is /usr/bin/python3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /home/michalz/.local/lib/python3.10/site-packages/PIL
Binary Pillow modules loaded from /home/michalz/.local/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.11.1
*** LITTLECMS2 support not installed
*** WEBP support not installed
*** AVIF support not installed
--- JPEG support ok, compiled for libjpeg-turbo 2.0.6
*** OPENJPEG (JPEG2000) support not installed
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.1-motley
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

Repro:

import PIL.Image
import numpy as np

def checkerboard(w, h):
    a = (np.arange(w).reshape((1, w, 1)) ^ np.arange(h).reshape((h, 1, 1))) & 1
    return a.astype(np.uint8) * np.uint8([255, 255, 255])

c = checkerboard(5, 19)
c[:9,:,1:3] = 0  # make top part red...
c[9,:,::2] = 0  # ...middle row green...
c[10:,:,0:2] = 0  # ...and bottom part blue
input = PIL.Image.fromarray(c)
resized = input.resize((5, 10), resample=PIL.Image.BOX)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions