mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 09:57:43 +03:00 
			
		
		
		
	If default conversion from P is RGB with transparency, convert to RGBA
This commit is contained in:
		
							parent
							
								
									5fe583598f
								
							
						
					
					
						commit
						fdfa9e8521
					
				| 
						 | 
				
			
			@ -42,10 +42,14 @@ def test_default():
 | 
			
		|||
 | 
			
		||||
    im = hopper("P")
 | 
			
		||||
    assert_image(im, "P", im.size)
 | 
			
		||||
    im = im.convert()
 | 
			
		||||
    assert_image(im, "RGB", im.size)
 | 
			
		||||
    im = im.convert()
 | 
			
		||||
    assert_image(im, "RGB", im.size)
 | 
			
		||||
    converted_im = im.convert()
 | 
			
		||||
    assert_image(converted_im, "RGB", im.size)
 | 
			
		||||
    converted_im = im.convert()
 | 
			
		||||
    assert_image(converted_im, "RGB", im.size)
 | 
			
		||||
 | 
			
		||||
    im.info["transparency"] = 0
 | 
			
		||||
    converted_im = im.convert()
 | 
			
		||||
    assert_image(converted_im, "RGBA", im.size)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# ref https://github.com/python-pillow/Pillow/issues/274
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -914,16 +914,18 @@ class Image:
 | 
			
		|||
 | 
			
		||||
        self.load()
 | 
			
		||||
 | 
			
		||||
        has_transparency = self.info.get("transparency") is not None
 | 
			
		||||
        if not mode and self.mode == "P":
 | 
			
		||||
            # determine default mode
 | 
			
		||||
            if self.palette:
 | 
			
		||||
                mode = self.palette.mode
 | 
			
		||||
            else:
 | 
			
		||||
                mode = "RGB"
 | 
			
		||||
            if mode == "RGB" and has_transparency:
 | 
			
		||||
                mode = "RGBA"
 | 
			
		||||
        if not mode or (mode == self.mode and not matrix):
 | 
			
		||||
            return self.copy()
 | 
			
		||||
 | 
			
		||||
        has_transparency = self.info.get("transparency") is not None
 | 
			
		||||
        if matrix:
 | 
			
		||||
            # matrix conversion
 | 
			
		||||
            if mode not in ("L", "RGB"):
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user