         case .scaleAspectFit:
             ratio = min(horizontalRatio, verticalRatio)
         default:
-            return resize(fits: size, quality: quality)
-        }
-        
-        let newSize = CGSize(width: (self.size.width * ratio).rounded(), height: (self.size.height * ratio).rounded())
-        return resize(fits: newSize, quality: quality)
-    }
-    /// Creates a rescaled copy of the image, taking into account its orientation.
+            return resize(fills: size, quality: quality)
+        }
+        
+        let newSize = CGSize(width: (scaledWidth * ratio).rounded(), height: (scaledHeight * ratio).rounded())
+        return resize(fills: newSize, quality: quality)
+    }
+    /// Creates a rescaled copy of the image, taking into account its orientation in pixels. Animated image supported.
     ///
     /// The image will be scaled disproportionately if necessary to fit the bounds specified by the parameter.
     ///

    ///
    /// - Returns: An image with rounded corners.
    public func round(_ cornerRadius: CGFloat, border borderWidth: CGFloat = 0.0) -> UIImage! {
        // Early fatal checking.
        guard cornerRadius >= 0.0 && borderWidth >= 0.0 else { return nil }
        
        // If the image does not have an alpha layer, add one
        guard let cgImage = self.alpha.cgImage, let colorSpace = cgImage.colorSpace else { return nil }
        // Build a context that's the same dimensions as the new size
        guard let context = CGContext(data: nil, width: cgImage.width, height: cgImage.height, bitsPerComponent: cgImage.bitsPerComponent, bytesPerRow: 0, space: colorSpace, bitmapInfo: cgImage.bitmapInfo.rawValue) else { return nil }
        // Create a clipping path with rounded corners
        context.beginPath()
        let roundedRect = CGRect(x: borderWidth, y: borderWidth, width: size.width - borderWidth * 2.0, height: size.height - borderWidth * 2.0)
        if cornerRadius == 0 {
            context.addRect(roundedRect)
        } else {

    ///
    /// - Returns: A copy of the receiver that is squared to the thumbnail size.
    public func thumbnail(squaresTo sizet: CGFloat, borderWidth: CGFloat = 0.0, cornerRadius: CGFloat = 0.0, quality: CGInterpolationQuality = .default) -> UIImage! {
        guard !animatable else { return UIImage.animatedImage(with: self.images!.flatMap({ _img in autoreleasepool{ _img.thumbnail(squaresTo: sizet, borderWidth: borderWidth, cornerRadius: cornerRadius, quality: quality) } }), duration: duration) }
        
        // Resize the original image.
        guard let resizedImage = resize(fits: CGSize(width: sizet, height: sizet), using: .scaleAspectFill, quality: quality) else { return nil }
        // Crop out any part of the image that's larger than the thumbnail size
        // The cropped rect must be centered on the resized image
        // Round the origin points so that the size isn't altered when CGRectIntegral is later invoked
        let croppedRect = CGRect(x: ((resizedImage.scaledWidth - sizet) * 0.5).rounded(), y: ((resizedImage.scaledHeight - sizet) * 0.5).rounded(), width: sizet, height: sizet)
        guard let croppedImage = resizedImage.crop(to: croppedRect) else { return nil }
        var borderedImage = croppedImage
        if borderWidth > 0.0 { borderedImage = croppedImage.bordered(borderWidth) }
