Repository navigation
Closed
Labels
Description
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?
- OS: macOS 26 Public Beta
- Python: python@3.13
- Pillow: 11.3
/opt/homebrew/Cellar/python@3.13/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/python@3.13/bin/python3.13
System Python files loaded from /opt/homebrew/opt/python@3.13/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 okOrigin Jpeg:
Output Png:

Activity
radarhere commentedon Aug 3, 2025
Interesting. While this is something worth investigating and solving, if you're looking for an immediate solution, I will point out that the problem doesn't occur without the resize operation. So you could quantize the image first, and then resize.
imfantuan commentedon Aug 3, 2025
Thank you sir.
imfantuan commentedon Aug 3, 2025
I found that quantizing first and then resizing will get a larger image, but it's still smaller than not quantizing at all.
radarhere commentedon Aug 5, 2025
I've created #9133 to resolve this.
For an immediate solution, I suggest converting to RGBA before quantizing.
imfantuan commentedon Aug 5, 2025
It works perfect now. THX!