-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Image.frombytes
throws on empty image
#7492
Comments
Looks like I constructed a minimal example incorrectly. The issue was actually from trying to render empty string, due to a pagination step in between getting the text and rendering it. In that case, the issue would actually be that updated the issue report |
ImageFont.getmask
and ImageFont.getbbox
fail for long stringsImageFont.frombytes
throws on empty image
ImageFont.frombytes
throws on empty imageImage.frombytes
throws on empty image
Ok, I've created PR #7493 to resolve this. See what you think. |
Why should What use is an empty image? Would it be better to raise because we're passing in "bad" input? Should the user be checking they're no passing in bad input? |
I haven't tried the new version personally, but if that test case passes, that should solve my issue. |
Using one of our test fonts, yes, it passes. Could you help address a concern that has been raised? Why is it useful to you to have an empty image? |
Well like the example code showed, I'm not explicitly trying to produce an empty image, that's just what ends up happening during an intermediate step. Basically my code can sometimes try to render text consisting of only whitespace, for which I suppose I could add pre-checks to ensure that doesn't happen, but from a type theory perspective does that mean I just have to always produce |
Thanks. Let's say The thing I'm trying to balance is: do we give the user an exception they need to handle, or a (useless?) empty image they need to handle in another place/way. |
Among other things, I can paste it onto another image. For my use case this is part of a renderer - I have a string and a location, I render the text and paste it onto the base image (with some decoration steps in between). Empty image allows me to not need to check exceptions just for rendering text from a font object. As for the useless part, I think an empty image is no less useless than an empty string. If you want to do the exception route, you should make it so that |
Thanks, that sounds reasonable. |
What did you do?
I have some code I use to render text as images. When trying to render an empty string, it fails on
Image.frombytes
What did you expect to happen?
I expected
Image.frombytes
with size(0, 0)
and bytes[]
(as a numpy array of uint8) to successfully yield an empty image.What actually happened?
An exception is thrown:
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: