mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 19:36:38 +03:00
Return copy on Image crop if crop dimensions match Image dimensions
This commit is contained in:
parent
2152b26515
commit
4dd7b94338
19
PIL/Image.py
19
PIL/Image.py
|
@ -1032,6 +1032,9 @@ class Image(object):
|
||||||
|
|
||||||
x0, y0, x1, y1 = map(int, map(round, box))
|
x0, y0, x1, y1 = map(int, map(round, box))
|
||||||
|
|
||||||
|
if x0 == 0 and y0 == 0 and (x1, y1) == self.size:
|
||||||
|
return self.copy()
|
||||||
|
|
||||||
if x1 < x0:
|
if x1 < x0:
|
||||||
x1 = x0
|
x1 = x0
|
||||||
if y1 < y0:
|
if y1 < y0:
|
||||||
|
@ -1520,16 +1523,16 @@ class Image(object):
|
||||||
def remap_palette(self, dest_map, source_palette=None):
|
def remap_palette(self, dest_map, source_palette=None):
|
||||||
"""
|
"""
|
||||||
Rewrites the image to reorder the palette.
|
Rewrites the image to reorder the palette.
|
||||||
|
|
||||||
:param dest_map: A list of indexes into the original palette.
|
:param dest_map: A list of indexes into the original palette.
|
||||||
e.g. [1,0] would swap a two item palette, and list(range(255))
|
e.g. [1,0] would swap a two item palette, and list(range(255))
|
||||||
is the identity transform.
|
is the identity transform.
|
||||||
:param source_palette: Bytes or None.
|
:param source_palette: Bytes or None.
|
||||||
:returns: An :py:class:`~PIL.Image.Image` object.
|
:returns: An :py:class:`~PIL.Image.Image` object.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from . import ImagePalette
|
from . import ImagePalette
|
||||||
|
|
||||||
if self.mode not in ("L", "P"):
|
if self.mode not in ("L", "P"):
|
||||||
raise ValueError("illegal image mode")
|
raise ValueError("illegal image mode")
|
||||||
|
|
||||||
|
@ -1538,7 +1541,7 @@ class Image(object):
|
||||||
source_palette = self.im.getpalette("RGB")[:768]
|
source_palette = self.im.getpalette("RGB")[:768]
|
||||||
else: # L-mode
|
else: # L-mode
|
||||||
source_palette = bytearray(i//3 for i in range(768))
|
source_palette = bytearray(i//3 for i in range(768))
|
||||||
|
|
||||||
|
|
||||||
palette_bytes = b""
|
palette_bytes = b""
|
||||||
new_positions = [0]*256
|
new_positions = [0]*256
|
||||||
|
@ -1591,8 +1594,8 @@ class Image(object):
|
||||||
size=len(palette_bytes))
|
size=len(palette_bytes))
|
||||||
|
|
||||||
return m_im
|
return m_im
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def resize(self, size, resample=NEAREST):
|
def resize(self, size, resample=NEAREST):
|
||||||
"""
|
"""
|
||||||
|
@ -2615,7 +2618,7 @@ def register_decoder(name, decoder):
|
||||||
:param decoder: A callable(mode, args) that returns an
|
:param decoder: A callable(mode, args) that returns an
|
||||||
ImageFile.PyDecoder object
|
ImageFile.PyDecoder object
|
||||||
|
|
||||||
.. versionadded:: 4.1.0
|
.. versionadded:: 4.1.0
|
||||||
"""
|
"""
|
||||||
DECODERS[name] = decoder
|
DECODERS[name] = decoder
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user