Skip to content

Commit

Permalink
🐛 (plugin): Add warning when using jpeg reconstruction for clarificat…
Browse files Browse the repository at this point in the history
…ion (#60)

* add warnings about jpeg reconstruction

* code format

* remove unused import
  • Loading branch information
Isotr0py authored Sep 2, 2024
1 parent 284a7f0 commit 060bedc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pillow_jxl/JpegXLImagePlugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from io import BytesIO

import PIL
Expand Down Expand Up @@ -94,6 +95,7 @@ def _save(im, fp, filename, save_all=False):
effort = info.get("effort", 7)
use_container = info.get("use_container", False)
use_original_profile = info.get("use_original_profile", False)
jpeg_encode = info.get("lossless_jpeg", True)

enc = Encoder(
mode=im.mode,
Expand All @@ -106,7 +108,12 @@ def _save(im, fp, filename, save_all=False):
)
# FIXME (Isotr0py): im.filename maybe None if parse stream
# TODO (Isotr0py): This part should be refactored in the near future
if im.format == "JPEG" and im.filename:
if im.format == "JPEG" and im.filename and jpeg_encode:
warnings.warn(
"Using JPEG reconstruction to create lossless JXL image from JPEG. "
"This is the default behavior for JPEG encode, if you want to "
"disable this, please set 'lossless_jpeg' to False."
)
with open(im.filename, "rb") as f:
data = enc(f.read(), im.width, im.height, jpeg_encode=True)
else:
Expand Down

0 comments on commit 060bedc

Please sign in to comment.