Skip to content

Keep ImageOps.contain() from rounding thin images to zero pixels - #10083

Closed
ekanshul wants to merge 1 commit into
python-pillow:mainfrom
ekanshul:fix/imageops-contain-narrow-zero
Closed

ekanshul wants to merge 1 commit into
python-pillow:mainfrom
ekanshul:fix/imageops-contain-narrow-zero

Conversation

@ekanshul

Copy link
Copy Markdown

Fixes #9997.

Changes proposed in this pull request:

  • Keep ImageOps.contain() from rounding a thin image's shorter side to zero pixels
  • ImageOps.pad() is fixed as well because it calls contain()
  • Tests for both cases and a 13.0.0 release note

contain() uses round() when scaling the shorter side. For a 100x1
image into a 10x10 box that becomes 0, and resize() raises
ValueError. Clamp the calculated dimension to at least one pixel so
contain() and pad() succeed.

Fixes python-pillow#9997
@radarhere

radarhere commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

This is a duplicate of #9998 and #9672.

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