You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It raises a TypeError that says in draw_rectangle function, width requires an integer but got a tuple.
What are your OS, Python and Pillow versions?
OS: Ubuntu
Python: 3.7.5
Pillow: 8.3.1
I find in PR #5552 ImageOps.expand was modified and add two lines of code to draw the output, which are not necessary.
I guess if it is code for debug. If not, please notice that border may be a tuple and can not be passed to draw.rectangle as width.
defexpand(image, border=0, fill=0):
""" Add border to the image :param image: The image to expand. :param border: Border width, in pixels. :param fill: Pixel fill value (a color value). Default is 0 (black). :return: An image. """left, top, right, bottom=_border(border)
width=left+image.size[0] +rightheight=top+image.size[1] +bottomcolor=_color(fill, image.mode)
ifimage.mode=="P"andimage.palette:
out=Image.new(image.mode, (width, height))
out.putpalette(image.palette)
out.paste(image, (left, top))
draw=ImageDraw.Draw(out)
draw.rectangle((0, 0, width, height), outline=color, width=border) # TypeError from hereelse:
out=Image.new(image.mode, (width, height), color)
out.paste(image, (left, top))
returnout
The text was updated successfully, but these errors were encountered:
It's not for debugging purposes. These lines are there to draw the fill color. If color is an RGB color, then it needs to be looked up in the image palette. This needs to be done on a new palette (to avoid modifying the original image if an additional paletter entry needs to be allocated). Without this draw operation, the border color would just be the zero index.
I've created #5615 to resolve this issue by changing the strategy. Instead, the PR creates a copy of the palette, calculates the palette index from that and uses it for the background color, and then attaches the new palette to the output image.
radarhere
changed the title
Bug in ImageOps.expand
ImageOps.expand error with tuple border
Jul 16, 2021
What did you do?
Call ImageOps.expand with a tuple
border
.What did you expect to happen?
Input image will be expanded.
What actually happened?
It raises a TypeError that says in draw_rectangle function,
width
requires an integer but got a tuple.What are your OS, Python and Pillow versions?
I find in PR #5552 ImageOps.expand was modified and add two lines of code to draw the output, which are not necessary.
I guess if it is code for debug. If not, please notice that
border
may be a tuple and can not be passed to draw.rectangle aswidth
.The text was updated successfully, but these errors were encountered: