mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-10-30 23:47:27 +03:00 
			
		
		
		
	Fix size calculation of Image.thumbnail()
This commit is contained in:
		
							parent
							
								
									29fee8fc43
								
							
						
					
					
						commit
						e9ef1d236d
					
				|  | @ -50,6 +50,14 @@ def test_aspect(): | |||
|     im.thumbnail((33, 33)) | ||||
|     assert im.size == (21, 33)  # ratio is 0.6363636364 | ||||
| 
 | ||||
|     im = Image.new("L", (145, 100))  # ratio is 1.45 | ||||
|     im.thumbnail((50, 50)) | ||||
|     assert im.size ==(50, 34)  # ratio is 1.47058823529 | ||||
| 
 | ||||
|     im = Image.new("L", (100, 145))  # ratio is 0.689655172414 | ||||
|     im.thumbnail((50, 50)) | ||||
|     assert im.size == (34, 50)  # ratio is 0.68 | ||||
| 
 | ||||
| 
 | ||||
| def test_float(): | ||||
|     im = Image.new("L", (128, 128)) | ||||
|  |  | |||
|  | @ -2237,19 +2237,18 @@ class Image: | |||
|         """ | ||||
| 
 | ||||
|         # preserve aspect ratio | ||||
|         x, y = self.size | ||||
|         if x > size[0]: | ||||
|             y = max(round(y * size[0] / x), 1) | ||||
|             x = round(size[0]) | ||||
|         if y > size[1]: | ||||
|             x = max(round(x * size[1] / y), 1) | ||||
|             y = round(size[1]) | ||||
|         size = x, y | ||||
|         box = None | ||||
|         x, y = size | ||||
|         aspect = self.width / self.height | ||||
|         if x / y >= aspect: | ||||
|             x = max(y * aspect, 1) | ||||
|         else: | ||||
|             y = max(x / aspect, 1) | ||||
|         size = (round(x), round(y)) | ||||
| 
 | ||||
|         if size == self.size: | ||||
|             return | ||||
| 
 | ||||
|         box = None | ||||
|         if reducing_gap is not None: | ||||
|             res = self.draft(None, (size[0] * reducing_gap, size[1] * reducing_gap)) | ||||
|             if res is not None: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user