SnapshotService.swift 589 Bytes
//
//  SnapshotService.swift
//  browser
//
//  Created by Artem Talko on 23.10.2023.
//

import UIKit
import WebKit

final class SnapshotService {
    static let shared = SnapshotService()
    let snapshotConfiguration = WKSnapshotConfiguration()
    
    private init() {}
    
    func makeSnapshot(_ viewForSnap: UIView) -> UIImage {
        let renderer = UIGraphicsImageRenderer(size: viewForSnap.bounds.size)
        let siteSnapshotImage = renderer.image { (context) in
            viewForSnap.layer.render(in: context.cgContext)
        }
        return siteSnapshotImage
    }
}