Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Apr 9, 2025

Resolves #8872

Looking at the specification, or even just looking at https://github.com/python-pillow/Pillow/blob/main/Tests/images/hopper.xpm#L50), you will see that an XPM image describes a palette with a series of keys and values, and then lists the pixel values within lines separated by quotes and commas. Our "raw" decoder cannot handle this pixel data, and I've created a Python decoder instead.

I've also pushed commits to read an image as RGB if the palette is larger than 256 colours (test image from the user in the issue), or if the palette keys are longer than a single character (test image created by ImageMagick), removing this error.

if pal > 256 or bpp != 1:
msg = "cannot read this XPM file"
raise ValueError(msg)

@radarhere radarhere changed the title Improved reading XPM images Improve reading XPM images Apr 19, 2025
@hugovk hugovk merged commit 3d21c16 into python-pillow:main Jun 27, 2025
55 checks passed
@radarhere radarhere deleted the xpm branch June 27, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageGrab.grabclipboard raises ValueError: cannot read this XPM file

2 participants