-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: buffer is not large enough #6507
Comments
On my macOS machine, the image won't open in Preview. If I try and use ImageMagick to convert it to a PNG, I get the following.
Is there any reason that you think the image isn't invalid? How was it created? |
The image is a mask. it has only 1 channel. I can only view it in PyCharm, It can not be opened on my win10 machine too. And it was created by pdfminer.image.ImageWriter. But I don't know the details. Maybe I should give them this issue |
You can choose to either try and convince us to be more lenient in reading your broken image, or to convince pdfminer to try and save a valid BMP file from your PDF. I would think that getting pdfminer to save a valid BMP file would be more helpful to you if you are planning to do other things with the BMP file than just pass it to Pillow, but it's up to you. |
In fact, I'm trying to convert PDF to Image in pure Python and Pillow. It's almost done. If you want this new feature, you'd better be more lenient. And I will get pdfminer to save a valid BMP file too. |
If you'd like an immediate solution, I've found that the following code works. from PIL import Image
with open("MX11.bmp", "rb") as f:
with Image.open(f) as im:
im.show() |
I've created PR #6510 to resolve this. |
I have the same issue when I download this file and try to open the it using this command: import requests
from PIL import Image
url = "https://www.jetify.com/favicon.ico"
resp = requests.get(url)
resp.raise_for_status()
with open("favicon.ico", "wb") as f:
f.write(r.content)
Image.open("favicon.ico") # --> ValueError: buffer is not large enough |
From what I can see, the image's transparency mask is truncated. I've created #8180. With that, setting import requests
from PIL import Image, ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
url = "https://www.jetify.com/favicon.ico"
resp = requests.get(url)
resp.raise_for_status()
with open("favicon.ico", "wb") as f:
f.write(resp.content)
Image.open("favicon.ico") |
What did you do?
I tried to open a bmp image and show it.
What did you expect to happen?
The image is opened and loaded normally.
What actually happened?
ValueError: buffer is not large enough
What are your OS, Python and Pillow versions?
MX11.zip
How to fix this?
I modified ImageFile.load method like this. Put ValueError in the Exception Tuple. It solved my problem. I wonder if there will be side effects.
The text was updated successfully, but these errors were encountered: