mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			18 lines
		
	
	
		
			647 B
		
	
	
	
		
			Swift
		
	
		
		
			
		
	
	
			18 lines
		
	
	
		
			647 B
		
	
	
	
		
			Swift
		
	
| 
											6 years ago
										 | 
 | ||
|  | extension UIImage { | ||
|  |      | ||
|  |     func scaled(to size: CGSize) -> UIImage { | ||
|  |         var rect = CGRect.zero | ||
|  |         let aspectRatio = min(size.width / self.size.width, size.height / self.size.height) | ||
|  |         rect.size.width = self.size.width * aspectRatio | ||
|  |         rect.size.height = self.size.height * aspectRatio | ||
|  |         rect.origin.x = (size.width - rect.size.width) / 2 | ||
|  |         rect.origin.y = (size.height - rect.size.height) / 2 | ||
|  |         UIGraphicsBeginImageContextWithOptions(size, false, 0) | ||
|  |         draw(in: rect) | ||
|  |         let result = UIGraphicsGetImageFromCurrentImageContext()! | ||
|  |         UIGraphicsEndImageContext() | ||
|  |         return result | ||
|  |     } | ||
|  | } |