mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Write support, fixes #602
This commit is contained in:
		
							parent
							
								
									2daac27713
								
							
						
					
					
						commit
						327ea209b8
					
				| 
						 | 
				
			
			@ -127,6 +127,11 @@ def _save(im, fp, filename):
 | 
			
		|||
        rawmode, head = "1;I", b"P4"
 | 
			
		||||
    elif im.mode == "L":
 | 
			
		||||
        rawmode, head = "L", b"P5"
 | 
			
		||||
    elif im.mode == "I":
 | 
			
		||||
        if im.getextrema()[1] < 2**16:
 | 
			
		||||
            rawmode, head = "I;16B", b"P5"
 | 
			
		||||
        else:
 | 
			
		||||
            rawmode, head = "I;32B", b"P5"
 | 
			
		||||
    elif im.mode == "RGB":
 | 
			
		||||
        rawmode, head = "RGB", b"P6"
 | 
			
		||||
    elif im.mode == "RGBA":
 | 
			
		||||
| 
						 | 
				
			
			@ -134,8 +139,15 @@ def _save(im, fp, filename):
 | 
			
		|||
    else:
 | 
			
		||||
        raise IOError("cannot write mode %s as PPM" % im.mode)
 | 
			
		||||
    fp.write(head + ("\n%d %d\n" % im.size).encode('ascii'))
 | 
			
		||||
    if head != b"P4":
 | 
			
		||||
    if head == b"P6":
 | 
			
		||||
        fp.write(b"255\n")
 | 
			
		||||
    if head == b"P5":
 | 
			
		||||
        if rawmode == "I":
 | 
			
		||||
            fp.write(b"255\n")
 | 
			
		||||
        elif rawmode == "I;16B":
 | 
			
		||||
            fp.write(b"65535\n")
 | 
			
		||||
        elif rawmode == "I;32B":
 | 
			
		||||
            fp.write(b"2147483648\n")
 | 
			
		||||
    ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, 1))])
 | 
			
		||||
 | 
			
		||||
    # ALTERNATIVE: save via builtin debug function
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user