Let negative crop values crop from right.

This commit is contained in:
voussoir 2020-09-23 12:47:44 -07:00
parent fde04ba088
commit 2a39ba4698

View file

@ -10,6 +10,14 @@ def crop(filename, crops, *, inplace=False):
i = Image.open(filename)
if len(crops) == 2:
crops.extend(i.size)
if crops[0] < 0: crops[0] = i.size[0] + crops[0]
if crops[1] < 0: crops[1] = i.size[1] + crops[1]
if crops[2] < 0: crops[2] = i.size[0] + crops[2]
if crops[3] < 0: crops[3] = i.size[1] + crops[3]
if crops[2] == 0: crops[2] = i.size[0]
if crops[3] == 0: crops[3] = i.size[1]
i = i.crop(crops)
if inplace:
newname = filename