mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-11 17:56:18 +03:00
Write JFIF header when saving JPEG
This commit is contained in:
parent
7fb21bcb62
commit
660894cd36
|
@ -91,15 +91,17 @@ class TestFileJpeg:
|
|||
assert k > 0.9
|
||||
|
||||
def test_dpi(self):
|
||||
def test(xdpi, ydpi=None):
|
||||
with Image.open(TEST_FILE) as im:
|
||||
im = self.roundtrip(im, dpi=(xdpi, ydpi or xdpi))
|
||||
return im.info.get("dpi")
|
||||
for test_image_path in [TEST_FILE, "Tests/images/pil_sample_cmyk.jpg"]:
|
||||
|
||||
assert test(72) == (72, 72)
|
||||
assert test(300) == (300, 300)
|
||||
assert test(100, 200) == (100, 200)
|
||||
assert test(0) is None # square pixels
|
||||
def test(xdpi, ydpi=None):
|
||||
with Image.open(test_image_path) as im:
|
||||
im = self.roundtrip(im, dpi=(xdpi, ydpi or xdpi))
|
||||
return im.info.get("dpi")
|
||||
|
||||
assert test(72) == (72, 72)
|
||||
assert test(300) == (300, 300)
|
||||
assert test(100, 200) == (100, 200)
|
||||
assert test(0) is None # square pixels
|
||||
|
||||
def test_icc(self, tmp_path):
|
||||
# Test ICC support
|
||||
|
|
|
@ -222,6 +222,7 @@ ImagingJpegEncode(Imaging im, ImagingCodecState state, UINT8* buf, int bytes)
|
|||
context->cinfo.smoothing_factor = context->smooth;
|
||||
context->cinfo.optimize_coding = (boolean) context->optimize;
|
||||
if (context->xdpi > 0 && context->ydpi > 0) {
|
||||
context->cinfo.write_JFIF_header = TRUE;
|
||||
context->cinfo.density_unit = 1; /* dots per inch */
|
||||
context->cinfo.X_density = context->xdpi;
|
||||
context->cinfo.Y_density = context->ydpi;
|
||||
|
|
Loading…
Reference in New Issue
Block a user