mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Added merging images example
This commit is contained in:
		
							parent
							
								
									475b7233d6
								
							
						
					
					
						commit
						b12c2fe682
					
				|  | @ -171,20 +171,37 @@ Rolling an image | ||||||
| 
 | 
 | ||||||
| :: | :: | ||||||
| 
 | 
 | ||||||
|     def roll(image, delta): |     def roll(im, delta): | ||||||
|         """Roll an image sideways.""" |         """Roll an image sideways.""" | ||||||
|         xsize, ysize = image.size |         xsize, ysize = im.size | ||||||
| 
 | 
 | ||||||
|         delta = delta % xsize |         delta = delta % xsize | ||||||
|         if delta == 0: |         if delta == 0: | ||||||
|             return image |             return im | ||||||
| 
 | 
 | ||||||
|         part1 = image.crop((0, 0, delta, ysize)) |         part1 = im.crop((0, 0, delta, ysize)) | ||||||
|         part2 = image.crop((delta, 0, xsize, ysize)) |         part2 = im.crop((delta, 0, xsize, ysize)) | ||||||
|         image.paste(part1, (xsize - delta, 0, xsize, ysize)) |         im.paste(part1, (xsize - delta, 0, xsize, ysize)) | ||||||
|         image.paste(part2, (0, 0, xsize - delta, ysize)) |         im.paste(part2, (0, 0, xsize - delta, ysize)) | ||||||
| 
 | 
 | ||||||
|         return image |         return im | ||||||
|  | 
 | ||||||
|  | Or if you would like to merge two images into a wider image: | ||||||
|  | 
 | ||||||
|  | Merging images | ||||||
|  | ^^^^^^^^^^^^^^ | ||||||
|  | 
 | ||||||
|  | :: | ||||||
|  | 
 | ||||||
|  |     def merge(im1, im2): | ||||||
|  |         w = im1.size[0] + im2.size[0] | ||||||
|  |         h = max(im1.size[1], im2.size[1]) | ||||||
|  |         im = Image.new("RGBA", (w, h)) | ||||||
|  | 
 | ||||||
|  |         im.paste(im1) | ||||||
|  |         im.paste(im2, (im1.size[0], 0)) | ||||||
|  | 
 | ||||||
|  |         return im | ||||||
| 
 | 
 | ||||||
| For more advanced tricks, the paste method can also take a transparency mask as | For more advanced tricks, the paste method can also take a transparency mask as | ||||||
| an optional argument. In this mask, the value 255 indicates that the pasted | an optional argument. In this mask, the value 255 indicates that the pasted | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user