Skip to content

Broken quantized png #9128

Description

@imfantuan

What did you do?

from PIL import Image
img = Image.open('plusx.jpg')
print(f"Original size: {img.size}, mode: {img.mode}")
resized = img.resize((img.width//2, img.height//2), Image.Resampling.LANCZOS)
quantized = resized.quantize(colors=256, method=3)
print(f"Quantized mode: {quantized.mode}, palette colors: {len(quantized.getpalette())//3}")
quantized.save('output_quantized.png')
print("Saved: output_quantized.png")

What did you expect to happen?

saved a nice quantized png

What actually happened?

saved a broken quantized png

What are your OS, Python and Pillow versions?

/opt/homebrew/Cellar/[email protected]/3.13.3_1/bin/python3  -m PIL --report
--------------------------------------------------------------------
Pillow 11.3.0
Python 3.13.3 (main, Apr  8 2025, 13:54:08) [Clang 17.0.0 (clang-1700.0.13.3)]
--------------------------------------------------------------------
Python executable is /opt/homebrew/opt/[email protected]/bin/python3.13
System Python files loaded from /opt/homebrew/opt/[email protected]/Frameworks/Python.framework/Versions/3.13
--------------------------------------------------------------------
Python Pillow modules loaded from /opt/homebrew/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from /opt/homebrew/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.5.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.1
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.12
--- LIBTIFF support ok, loaded 4.7.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.2
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok

Origin Jpeg:

https://demopub.s3.us-west-000.backblazeb2.com/plusx.jpg

Output Png:

Image

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