Skip to content

Keep contain() dimensions at a minimum of one pixel - #10034

Closed
fahadhewad wants to merge 1 commit into
python-pillow:mainfrom
fahadhewad:contain-minimum-one-pixel
Closed

fahadhewad wants to merge 1 commit into
python-pillow:mainfrom
fahadhewad:contain-minimum-one-pixel

Conversation

@fahadhewad

@fahadhewad fahadhewad commented Sep 21, 2026

Copy link
Copy Markdown

Fixes #9997. Alternative to #9673

Changes proposed in this pull request:

  • ImageOps.contain() works out the second dimension with round(), which can come out as zero for a very narrow image, and resize() then fails with "height and width must be > 0". Keep that dimension at one pixel or more.
  • ImageOps.pad() failed the same way, since it calls contain().
  • Add a test for 100x1, 1x100, 20x1 and 1x20 images contained and padded into a 10x10 box.

ImageOps.contain() derives the second dimension with round(), which can
come out as zero for a very narrow image, and resize() then fails with
"height and width must be > 0". ImageOps.pad() raised the same error,
since it calls contain().
@radarhere

radarhere commented Sep 21, 2026

Copy link
Copy Markdown
Member

Hi. This is a duplicate of #9998 and #9672.

#9673 is an alternative solution. Do you object to that in any way?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageOps.contain and pad fail when a narrow image rounds to zero pixels

2 participants