admin管理员组

文章数量:1305218

I'm trying to setup a widget to pull an image down from a webserver and I'm running into an error of Widget archival failed due to image being too large [9] - (1024, 1024), totalArea: 1048576 > max[718080.000000].

I've tried two different approaches to resolve this error and both have failed to resolve the image.

Is there another approach I could take on addressing this issue so the image appears on the widge?

Simple approach

extension UIImage {
  func resized(toWidth width: CGFloat, isOpaque: Bool = true) -> UIImage? {
    let canvas = CGSize(width: width, height: CGFloat(ceil(width/size.width * size.height)))
    let format = imageRendererFormat
    format.opaque = isOpaque
    return UIGraphicsImageRenderer(size: canvas, format: format).image {
      _ in draw(in: CGRect(origin: .zero, size: canvas))
    }
  }
}
extension UIImage {
    /// Resize the image to strictly fit within WidgetKit’s max allowed pixel area (718,080 pixels)
    func resizedForWidget(maxArea: CGFloat = 718_080.0, isOpaque: Bool = true) -> UIImage? {
        let originalWidth = size.width
        let originalHeight = size.height
        let originalArea = originalWidth * originalHeight

        print("

本文标签: swiftWidget archival failed due to image being too largeStack Overflow