Skip to content

fix: Fix for Pillow error when extracting PNG images #3998

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025

Conversation

awalker4
Copy link
Contributor

@awalker4 awalker4 commented May 8, 2025

When I tried to partition a PNG file and extract images, I got an error from Pillow:

WARNING  unstructured:pdf_image_utils.py:230 Image Extraction Error: Skipping the failed image
Traceback (most recent call last):
  File "/Users/austin/.pyenv/versions/unstructured/lib/python3.10/site-packages/PIL/JpegImagePlugin.py", line 666, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

The issue is that a PNG has an additional layer that cannot be saved off in jpeg format. We can fix this with a quick conversion. I added a png test case that is now passing with this fix.

When I tried to partition a PNG file and extract images, I got an error from Pillow:

```
WARNING  unstructured:pdf_image_utils.py:230 Image Extraction Error: Skipping the failed image
Traceback (most recent call last):
  File "/Users/austin/.pyenv/versions/unstructured/lib/python3.10/site-packages/PIL/JpegImagePlugin.py", line 666, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'
```

The issue is that a PNG has an additional layer that cannot be saved off in jpeg format. We can fix
this with a quick conversion. I added a png test case that is now passing with this fix.
@awalker4 awalker4 enabled auto-merge May 8, 2025 21:51
@awalker4 awalker4 added this pull request to the merge queue May 8, 2025
Merged via the queue into main with commit e3417d7 May 8, 2025
43 checks passed
@awalker4 awalker4 deleted the fix/PNG-image-extraction branch May 8, 2025 22:26
Copy link
Contributor

@ajjimeno ajjimeno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants