mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Use getpalette() in ImageOps
This commit is contained in:
parent
c0aaf54816
commit
279ddf4ce6
|
@ -130,6 +130,20 @@ def test_pad():
|
|||
)
|
||||
|
||||
|
||||
def test_palette():
|
||||
im = hopper("P")
|
||||
|
||||
# Expand
|
||||
expanded_im = ImageOps.expand(im)
|
||||
assert_image_equal(im.convert("RGB"), expanded_im.convert("RGB"))
|
||||
|
||||
# Pad
|
||||
padded_im = ImageOps.pad(im, (256, 128), centering=(0, 0))
|
||||
assert_image_equal(
|
||||
im.convert("RGB"), padded_im.convert("RGB").crop((0, 0, 128, 128))
|
||||
)
|
||||
|
||||
|
||||
def test_pil163():
|
||||
# Division by zero in equalize if < 255 pixels in image (@PIL163)
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import functools
|
|||
import operator
|
||||
import re
|
||||
|
||||
from . import Image
|
||||
from . import Image, ImagePalette
|
||||
|
||||
#
|
||||
# helpers
|
||||
|
@ -292,7 +292,7 @@ def pad(image, size, method=Image.Resampling.BICUBIC, color=None, centering=(0.5
|
|||
else:
|
||||
out = Image.new(image.mode, size, color)
|
||||
if resized.palette:
|
||||
out.putpalette(resized.palette)
|
||||
out.putpalette(resized.getpalette())
|
||||
if resized.width != size[0]:
|
||||
x = int((size[0] - resized.width) * max(0, min(centering[0], 1)))
|
||||
out.paste(resized, (x, 0))
|
||||
|
@ -399,8 +399,7 @@ def expand(image, border=0, fill=0):
|
|||
height = top + image.size[1] + bottom
|
||||
color = _color(fill, image.mode)
|
||||
if image.mode == "P" and image.palette:
|
||||
image.load()
|
||||
palette = image.palette.copy()
|
||||
palette = ImagePalette.ImagePalette(palette=image.getpalette())
|
||||
if isinstance(color, tuple):
|
||||
color = palette.getcolor(color)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user