         color.setFill()
         context.fill(rect)
         
-        let image = UIGraphicsGetImageFromCurrentImageContext()
-        UIGraphicsEndImageContext()
-        
-        return image
+        return UIGraphicsGetImageFromCurrentImageContext()
     }
     /// Creates an image from any instances of `CGPDFDocument` with the specific size and tint color.
     ///

    /// Creates and render a snapshot of the view hierarchy into the current context. Returns nil if the snapshot is missing image data, an image object if the snapshot is complete.
    public var contents: UIImage! {
        UIGraphicsBeginImageContextWithOptions(bounds.size, isOpaque, UIScreen.main.scale)
        if #available(iOS 7.0, *) {
            if !drawHierarchy(in: bounds, afterScreenUpdates: false) {
                guard let context = UIGraphicsGetCurrentContext() else { return nil }

import UIKit
import ImageIO
import Accelerate
import Foundation
import CoreGraphics
import AVFoundation

