diff --git a/damus/Views/ProfilePicView.swift b/damus/Views/ProfilePicView.swift index 297a786..69be4b8 100644 --- a/damus/Views/ProfilePicView.swift +++ b/damus/Views/ProfilePicView.swift @@ -55,6 +55,7 @@ struct InnerProfilePicView: View { KFAnimatedImage(url) .callbackQueue(.dispatch(.global(qos: .background))) .processingQueue(.dispatch(.global(qos: .background))) + .appendProcessor(LargeImageProcessor()) .configure { view in view.framePreloadCount = 1 } @@ -104,6 +105,30 @@ struct ProfilePicView: View { } } +struct LargeImageProcessor: ImageProcessor { + + let identifier: String = "com.damus.largeimageprocessor" + let maxSize: Int = 1000000 + let downsampleSize = CGSize(width: 200, height: 200) + + func process(item: ImageProcessItem, options: KingfisherParsedOptionsInfo) -> KFCrossPlatformImage? { + let downsamplingImageProcessor = DownsamplingImageProcessor(size: downsampleSize) + + switch item { + case .image(let image): + if image.cacheCost > maxSize { + return downsamplingImageProcessor.process(item: item, options: options) + } + return image + case .data(let data): + if data.count > maxSize { + return downsamplingImageProcessor.process(item: item, options: options) + } + return KFCrossPlatformImage(data: data) + } + } +} + func get_profile_url(picture: String?, pubkey: String, profiles: Profiles) -> URL { let pic = picture ?? profiles.lookup(id: pubkey)?.picture ?? robohash(pubkey) if let url = URL(string: pic) {