Skip to content
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

ValueError: unknown raw mode for given image mode #6383

Closed
Darkpingouin opened this issue Jun 20, 2022 · 1 comment · Fixed by #6384
Closed

ValueError: unknown raw mode for given image mode #6383

Darkpingouin opened this issue Jun 20, 2022 · 1 comment · Fixed by #6384
Labels

Comments

@Darkpingouin
Copy link

Darkpingouin commented Jun 20, 2022

What did you do?

I tried to save a BMP Image

What did you expect to happen?

Have the image saved

What actually happened?

I got a ValueError: unknown raw mode for given image mode error

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 22.04 LTS
  • Python: 3.10.4
  • Pillow: 9.1.1

Here is the link to the stackoverflow post with stuff i tried

from io import BytesIO

from PIL import Image


def get_img_base64(filename):
    # Open Image
    image = Image.open(filename)
    # Saving the format
    format = image.format
    buffered = BytesIO()
    image.save(buffered, format)  # CRASH HERE
    img_str = base64.b64encode(buffered.getvalue())
    return "data:image/" + format + ";base64," + img_str.decode()


get_img_base64("IMG.BMP")

Traceback of the error :

Traceback (most recent call last):
  File "test.py", line XXX, in XXX
    imgBase64 = get_img_base64(path)
  File "test.py", line XXX, in get_img_base64
    image.save(buffered, format)
  File "python3.10/site-packages/PIL/Image.py", line 2264, in save
    self._ensure_mutable()
  File "python3.10/site-packages/PIL/Image.py", line 626, in _ensure_mutable
    self._copy()
  File "python3.10/site-packages/PIL/Image.py", line 619, in _copy
    self.load()
  File "python3.10/site-packages/PIL/ImageFile.py", line 234, in load
    err_code = decoder.decode(b"")[1]
  File "python3.10/site-packages/PIL/BmpImagePlugin.py", line 326, in decode
    self.set_as_raw(bytes(data), ("P", 0, self.args[-1]))
  File "python3.10/site-packages/PIL/ImageFile.py", line 684, in set_as_raw
    d = Image._getdecoder(self.mode, "raw", (rawmode))
  File "python3.10/site-packages/PIL/Image.py", line 435, in _getdecoder
    return decoder(mode, *args + extra)
ValueError: unknown raw mode for given image mode

Link to the image to reproduce

Just doing Image.open('YOURIMAGE').convert('RGB') causes the error

@radarhere radarhere changed the title PILLOW throws ValueError: unknown raw mode for given image mode ValueError: unknown raw mode for given image mode Jun 20, 2022
@radarhere
Copy link
Member

I've created PR #6384 to resolve this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants