Fix 0-size edge case in ImageOps.contain#9672
Conversation
|
An alternative way of fixing this problem would be to actually return an image with zero width (or height). We don't have to resize the existing image - if Regardless though, just as an aside... the visual output of this is still unsatisfying, right? As in, I expect you have a large collection of images, and you're looking to display all of them in a smaller way within boxes, so that a user can view all of them at once. But there's no way that the final output with one dimension being 1px is actually something that the user can easily interpret. |
|
In my case, I'm scaling it down to speed up subsequent color analysis, so looking pretty isn't a concern, but I understand this is not the most common usecase. For user-facing applications, I believe e.g. Windows does just give you a 1px-wide image. Twitter puts a limit on the aspect ratio and switch to cropping if the image is beyond it, but I'm not sure if that's a good fit for a primitive such as this. I'm not sure how well images with a dimension of 0 work in the rest of Pillow, but I assume there's a good reason why Image.resize refuses to produce them. :P |
|
Zero size images are permitted, except for some early Pillow versions. The error when resizing an image was added in #1714. I don't mind it as a error that communicates 'There's no way that you actually wanted this, you must have done something wrong'. If anyone could provide an argument as to why you would ever want to use I've created #9673 as an alternative, to allow |
Alternative to #9673
I ran into
ValueError: height and width must be > 0when trying to contain a very skinny image in a very small box. This fixes that.