Skip to content Skip to sidebar Skip to footer

Error In Draw.rectangle([x1, Y1, X2, Y2], Fill="black") When Drawing Rectangle With Pil For High Dimension Images

I'm getting Error in draw.rectangle([x1, y1, x2, y2], fill='Black') when drawing rectangle with PIL python library for high dimension png file(770x1024). But it works for medium si

Solution 1:

I suspect the problem is that when you open a smallish image, it has fewer pixels and fewer colours and is therefore more likely a palettised image rather than a full-colour RGB image - see here for explanation.

So, I suggest you change to this at the start of your program:

# Open image and ensure it is 3-channel RGB, not palettisedimg = Image.open(BytesIO(file_byte_string)).convert('RGB')

Post a Comment for "Error In Draw.rectangle([x1, Y1, X2, Y2], Fill="black") When Drawing Rectangle With Pil For High Dimension Images"