Use pathclass in resize.py.

This commit is contained in:
voussoir 2021-03-03 12:39:39 -08:00
parent 945bdec3d5
commit 4a61cb08e2
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -4,6 +4,7 @@ from PIL import Image
import sys import sys
from voussoirkit import imagetools from voussoirkit import imagetools
from voussoirkit import pathclass
from voussoirkit import winglob from voussoirkit import winglob
def resize( def resize(
@ -16,7 +17,8 @@ def resize(
only_shrink=False, only_shrink=False,
scale=None, scale=None,
): ):
i = Image.open(filename) file = pathclass.Path(filename)
i = Image.open(file.absolute_path)
(image_width, image_height) = i.size (image_width, image_height) = i.size
@ -50,12 +52,17 @@ def resize(
i = i.resize( (new_x, new_y), Image.ANTIALIAS) i = i.resize( (new_x, new_y), Image.ANTIALIAS)
if inplace: if inplace:
newname = filename new_name = file
else: else:
suffix = '_{width}x{height}'.format(width=new_x, height=new_y) suffix = '_{width}x{height}'.format(width=new_x, height=new_y)
(base, extension) = os.path.splitext(filename) base = file.replace_extension('').basename
newname = base + suffix + extension new_name = base + suffix + file.extension.with_dot
i.save(newname, quality=100) new_name = file.parent.with_child(new_name)
if new_name.extension == '.jpg':
i = i.convert('RGB')
i.save(new_name.absolute_path, quality=100)
def resize_argparse(args): def resize_argparse(args):