Merge pull request #4639 from radarhere/jfif

Write JFIF header when saving JPEG
This commit is contained in:
Hugo van Kemenade 2020-06-20 15:54:11 +03:00 committed by GitHub
commit bcb8cbbf22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -90,9 +90,12 @@ class TestFileJpeg:
] ]
assert k > 0.9 assert k > 0.9
def test_dpi(self): @pytest.mark.parametrize(
"test_image_path", [TEST_FILE, "Tests/images/pil_sample_cmyk.jpg"],
)
def test_dpi(self, test_image_path):
def test(xdpi, ydpi=None): def test(xdpi, ydpi=None):
with Image.open(TEST_FILE) as im: with Image.open(test_image_path) as im:
im = self.roundtrip(im, dpi=(xdpi, ydpi or xdpi)) im = self.roundtrip(im, dpi=(xdpi, ydpi or xdpi))
return im.info.get("dpi") return im.info.get("dpi")

View File

@ -222,6 +222,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
context->cinfo.smoothing_factor = context->smooth; context->cinfo.smoothing_factor = context->smooth;
context->cinfo.optimize_coding = (boolean) context->optimize; context->cinfo.optimize_coding = (boolean) context->optimize;
if (context->xdpi > 0 && context->ydpi > 0) { if (context->xdpi > 0 && context->ydpi > 0) {
context->cinfo.write_JFIF_header = TRUE;
context->cinfo.density_unit = 1; /* dots per inch */ context->cinfo.density_unit = 1; /* dots per inch */
context->cinfo.X_density = context->xdpi; context->cinfo.X_density = context->xdpi;
context->cinfo.Y_density = context->ydpi; context->cinfo.Y_density = context->ydpi;