Continuing former discussions about changing the resizing rule of the thumbnail to Aspect Fill
There’s very elegant solution with only 4 lines changed inside the method:
func resizedImage(withBounds bounds: CGSize) -> UIImage {
...
let ratio = max(horizontalRatio, verticalRatio) //Change the ratio to the maximum one
...
UIGraphicsBeginImageContextWithOptions(bounds, true, 0) //Cut the image to the given bounds
let originPoint = CGPoint(x: min((bounds.width - newSize.width), CGPoint.zero.x), y: min((bounds.height - newSize.height), CGPoint.zero.y)) //Calculating origin point to center the image
draw(in: CGRect(origin: originPoint, size: newSize)) //Using the originPoint
...
}
This put it to the center. The simplest way to check it is to test the three versions of the code (one in the book, your solution’s one, and one with my version of the originPoint using panoramic pictures.