mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Improved efficient saving by copying the saved image, instead of saving the same image twice
This commit is contained in:
		
							parent
							
								
									de80b8f36b
								
							
						
					
					
						commit
						6af53a7303
					
				| 
						 | 
					@ -311,20 +311,18 @@ def _save(im, fp, filename):
 | 
				
			||||||
    # create the temporary set of pngs
 | 
					    # create the temporary set of pngs
 | 
				
			||||||
    iconset = tempfile.mkdtemp('.iconset')
 | 
					    iconset = tempfile.mkdtemp('.iconset')
 | 
				
			||||||
    last_w = None
 | 
					    last_w = None
 | 
				
			||||||
    last_im = None
 | 
					 | 
				
			||||||
    for w in [16, 32, 128, 256, 512]:
 | 
					    for w in [16, 32, 128, 256, 512]:
 | 
				
			||||||
        prefix = 'icon_{}x{}'.format(w, w)
 | 
					        prefix = 'icon_{}x{}'.format(w, w)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        first_path = os.path.join(iconset, prefix+'.png')
 | 
				
			||||||
        if last_w == w:
 | 
					        if last_w == w:
 | 
				
			||||||
            im_scaled = last_im
 | 
					            shutil.copyfile(second_path, first_path)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            im_scaled = im.resize((w, w), Image.LANCZOS)
 | 
					            im.resize((w, w), Image.LANCZOS).save(first_path)
 | 
				
			||||||
        im_scaled.save(os.path.join(iconset, prefix+'.png'))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        im_scaled = im.resize((w*2, w*2), Image.LANCZOS)
 | 
					        second_path = os.path.join(iconset, prefix+'@2x.png')
 | 
				
			||||||
        im_scaled.save(os.path.join(iconset, prefix+'@2x.png'))
 | 
					        im.resize((w*2, w*2), Image.LANCZOS).save(second_path)
 | 
				
			||||||
        last_w = w*2
 | 
					        last_w = w*2
 | 
				
			||||||
        last_im = im_scaled
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # iconutil -c icns -o {} {}
 | 
					    # iconutil -c icns -o {} {}
 | 
				
			||||||
    from subprocess import Popen, PIPE, CalledProcessError
 | 
					    from subprocess import Popen, PIPE, CalledProcessError
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user