mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #7345 from radarhere/jpeg
This commit is contained in:
		
						commit
						d80610822f
					
				| 
						 | 
					@ -214,13 +214,20 @@ class TestFileJpeg:
 | 
				
			||||||
            # Should not raise OSError for image with icc larger than image size.
 | 
					            # Should not raise OSError for image with icc larger than image size.
 | 
				
			||||||
            im.save(
 | 
					            im.save(
 | 
				
			||||||
                f,
 | 
					                f,
 | 
				
			||||||
                format="JPEG",
 | 
					 | 
				
			||||||
                progressive=True,
 | 
					                progressive=True,
 | 
				
			||||||
                quality=95,
 | 
					                quality=95,
 | 
				
			||||||
                icc_profile=icc_profile,
 | 
					                icc_profile=icc_profile,
 | 
				
			||||||
                optimize=True,
 | 
					                optimize=True,
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with Image.open("Tests/images/flower2.jpg") as im:
 | 
				
			||||||
 | 
					            f = str(tmp_path / "temp2.jpg")
 | 
				
			||||||
 | 
					            im.save(f, progressive=True, quality=94, icc_profile=b" " * 53955)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        with Image.open("Tests/images/flower2.jpg") as im:
 | 
				
			||||||
 | 
					            f = str(tmp_path / "temp3.jpg")
 | 
				
			||||||
 | 
					            im.save(f, progressive=True, quality=94, exif=b" " * 43668)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_optimize(self):
 | 
					    def test_optimize(self):
 | 
				
			||||||
        im1 = self.roundtrip(hopper())
 | 
					        im1 = self.roundtrip(hopper())
 | 
				
			||||||
        im2 = self.roundtrip(hopper(), optimize=0)
 | 
					        im2 = self.roundtrip(hopper(), optimize=0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -797,10 +797,14 @@ def _save(im, fp, filename):
 | 
				
			||||||
            bufsize = 2 * im.size[0] * im.size[1]
 | 
					            bufsize = 2 * im.size[0] * im.size[1]
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            bufsize = im.size[0] * im.size[1]
 | 
					            bufsize = im.size[0] * im.size[1]
 | 
				
			||||||
 | 
					        if exif:
 | 
				
			||||||
 | 
					            bufsize += len(exif) + 5
 | 
				
			||||||
 | 
					        if extra:
 | 
				
			||||||
 | 
					            bufsize += len(extra) + 1
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
        # The EXIF info needs to be written as one block, + APP1, + one spare byte.
 | 
					        # The EXIF info needs to be written as one block, + APP1, + one spare byte.
 | 
				
			||||||
        # Ensure that our buffer is big enough. Same with the icc_profile block.
 | 
					        # Ensure that our buffer is big enough. Same with the icc_profile block.
 | 
				
			||||||
    bufsize = max(ImageFile.MAXBLOCK, bufsize, len(exif) + 5, len(extra) + 1)
 | 
					        bufsize = max(bufsize, len(exif) + 5, len(extra) + 1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize)
 | 
					    ImageFile._save(im, fp, [("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user