diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a7742e7af..2c742a6b1 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2189,7 +2189,7 @@ class Image: filename = str(fp) open_fp = True elif isPath(fp): - filename = fp + filename = os.fsdecode(fp) open_fp = True elif fp == sys.stdout: try: @@ -2209,7 +2209,7 @@ class Image: preinit() - ext = os.fsdecode(os.path.splitext(filename)[1].lower()) + ext = os.path.splitext(filename)[1].lower() if not format: if ext not in EXTENSION: diff --git a/src/PIL/Jpeg2KImagePlugin.py b/src/PIL/Jpeg2KImagePlugin.py index 8e0ff0735..0904b241b 100644 --- a/src/PIL/Jpeg2KImagePlugin.py +++ b/src/PIL/Jpeg2KImagePlugin.py @@ -317,7 +317,7 @@ def _accept(prefix): def _save(im, fp, filename): - if os.fsdecode(os.path.splitext(filename)[1]) == ".j2k": + if filename.endswith(".j2k"): kind = "j2k" else: kind = "jp2"