mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	Added support for generators when using append_images for WEBP
This commit is contained in:
		
							parent
							
								
									6c6f95f1d6
								
							
						
					
					
						commit
						bfaa0a1f07
					
				| 
						 | 
					@ -167,7 +167,7 @@ class WebPImageFile(ImageFile.ImageFile):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _save_all(im, fp, filename):
 | 
					def _save_all(im, fp, filename):
 | 
				
			||||||
    encoderinfo = im.encoderinfo.copy()
 | 
					    encoderinfo = im.encoderinfo.copy()
 | 
				
			||||||
    append_images = encoderinfo.get("append_images", [])
 | 
					    append_images = list(encoderinfo.get("append_images", []))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # If total frame count is 1, then save using the legacy API, which
 | 
					    # If total frame count is 1, then save using the legacy API, which
 | 
				
			||||||
    # will preserve non-alpha modes
 | 
					    # will preserve non-alpha modes
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -65,12 +65,7 @@ class TestFileWebpAnimation(PillowTestCase):
 | 
				
			||||||
        are visually similar to the originals.
 | 
					        are visually similar to the originals.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        temp_file = self.tempfile("temp.webp")
 | 
					        def check(temp_file):
 | 
				
			||||||
        frame1 = Image.open('Tests/images/anim_frame1.webp')
 | 
					 | 
				
			||||||
        frame2 = Image.open('Tests/images/anim_frame2.webp')
 | 
					 | 
				
			||||||
        frame1.save(temp_file,
 | 
					 | 
				
			||||||
            save_all=True, append_images=[frame2], lossless=True)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            im = Image.open(temp_file)
 | 
					            im = Image.open(temp_file)
 | 
				
			||||||
            self.assertEqual(im.n_frames, 2)
 | 
					            self.assertEqual(im.n_frames, 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,6 +78,23 @@ class TestFileWebpAnimation(PillowTestCase):
 | 
				
			||||||
            im.load()
 | 
					            im.load()
 | 
				
			||||||
            self.assert_image_equal(im, frame2.convert("RGBA"))
 | 
					            self.assert_image_equal(im, frame2.convert("RGBA"))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        frame1 = Image.open('Tests/images/anim_frame1.webp')
 | 
				
			||||||
 | 
					        frame2 = Image.open('Tests/images/anim_frame2.webp')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        temp_file1 = self.tempfile("temp.webp")
 | 
				
			||||||
 | 
					        frame1.copy().save(temp_file1,
 | 
				
			||||||
 | 
					            save_all=True, append_images=[frame2], lossless=True)
 | 
				
			||||||
 | 
					        check(temp_file1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # Tests appending using a generator
 | 
				
			||||||
 | 
					        def imGenerator(ims):
 | 
				
			||||||
 | 
					            for im in ims:
 | 
				
			||||||
 | 
					                yield im
 | 
				
			||||||
 | 
					        temp_file2 = self.tempfile("temp_generator.webp")
 | 
				
			||||||
 | 
					        frame1.copy().save(temp_file2,
 | 
				
			||||||
 | 
					            save_all=True, append_images=imGenerator([frame2]), lossless=True)
 | 
				
			||||||
 | 
					        check(temp_file2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_timestamp_and_duration(self):
 | 
					    def test_timestamp_and_duration(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        Try passing a list of durations, and make sure the encoded
 | 
					        Try passing a list of durations, and make sure the encoded
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user