Skip to content

Commit

Permalink
disable jpeg encode warning when lossless_jpeg=True
Browse files Browse the repository at this point in the history
  • Loading branch information
Piezoid committed Oct 10, 2024
1 parent 1719d2f commit ba642be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions pillow_jxl/JpegXLImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,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)
jpeg_encode = info.get("lossless_jpeg", None)
num_threads = info.get("num_threads", -1)

enc = Encoder(
Expand All @@ -113,12 +113,13 @@ 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 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."
)
if im.format == "JPEG" and im.filename and (jpeg_encode or jpeg_encode is None):
if jpeg_encode is None:
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'."
)
with open(im.filename, "rb") as f:
data = enc(f.read(), im.width, im.height, jpeg_encode=True)
else:
Expand Down
2 changes: 1 addition & 1 deletion test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_encode(image):
def test_jpeg_encode():
temp = tempfile.mktemp(suffix=".jxl")
img_ori = Image.open("test/images/sample.jpg")
img_ori.save(temp, lossless=True)
img_ori.save(temp, lossless=True, lossless_jpeg=True)

img_enc = Image.open(temp)
assert img_ori.size == img_enc.size == (40, 50)
Expand Down

0 comments on commit ba642be

Please sign in to comment.