diff --git a/tests/draw/test_image.py b/tests/draw/test_image.py
index bab8020184..6eaff9b3c5 100644
--- a/tests/draw/test_image.py
+++ b/tests/draw/test_image.py
@@ -2,7 +2,8 @@
import pytest
-from ..testing_utils import assert_no_logs, capture_logs
+from ..testing_utils import (
+ FakeHTML, assert_no_logs, capture_logs, resource_filename)
centered_image = '''
________
@@ -578,3 +579,15 @@ def test_image_exif_image_orientation(assert_same_renderings):
''',
tolerance=25,
)
+
+
+@assert_no_logs
+def test_image_exif_image_orientation_keep_format():
+ # Regression test for https://github.com/Kozea/WeasyPrint/issues/1755
+ pdf = FakeHTML(
+ string='''
+
+ ''',
+ base_url=resource_filename('')).write_pdf()
+ assert b'DCTDecode' in pdf
diff --git a/weasyprint/images.py b/weasyprint/images.py
index 290b52851a..e10d230b63 100644
--- a/weasyprint/images.py
+++ b/weasyprint/images.py
@@ -135,6 +135,8 @@ def get_image_from_uri(cache, url_fetcher, optimize_size, url,
else:
# Store image id to enable cache in Stream.add_image
image_id = md5(url.encode()).hexdigest()
+ # Keep image format as it is discarded by transposition
+ image_format = pillow_image.format
if orientation == 'from-image':
if 'exif' in pillow_image.info:
pillow_image = ImageOps.exif_transpose(
@@ -148,6 +150,7 @@ def get_image_from_uri(cache, url_fetcher, optimize_size, url,
if flip:
pillow_image = pillow_image.transpose(
Image.Transpose.FLIP_LEFT_RIGHT)
+ pillow_image.format = image_format
image = RasterImage(pillow_image, image_id, optimize_size)
except (URLFetchingError, ImageLoadingError) as exception: