2020-08-05 13:48:50 +02:00
|
|
|
// Copyright © 2020 Metabolist. All rights reserved.
|
|
|
|
|
2021-01-08 03:29:08 +01:00
|
|
|
import Kingfisher
|
2020-09-05 04:31:43 +02:00
|
|
|
import SwiftUI
|
2020-08-05 13:48:50 +02:00
|
|
|
|
|
|
|
extension KingfisherOptionsInfo {
|
|
|
|
static func downsampled(size: CGSize, scaleFactor: CGFloat, rounded: Bool = true) -> Self {
|
|
|
|
var processor: ImageProcessor = DownsamplingImageProcessor(size: size)
|
|
|
|
|
|
|
|
if rounded {
|
|
|
|
processor = processor.append(another: RoundCornerImageProcessor(radius: .widthFraction(0.5)))
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
.processor(processor),
|
|
|
|
.scaleFactor(scaleFactor),
|
|
|
|
.cacheOriginalImage,
|
|
|
|
.cacheSerializer(FormatIndicatedCacheSerializer.png)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
static func downsampled(dimension: CGFloat, scaleFactor: CGFloat, rounded: Bool = true) -> Self {
|
|
|
|
downsampled(size: CGSize(width: dimension, height: dimension), scaleFactor: scaleFactor, rounded: rounded)
|
|
|
|
}
|
|
|
|
}
|
2021-01-08 03:29:08 +01:00
|
|
|
|
|
|
|
extension KFOptionSetter {
|
|
|
|
func downsampled(size: CGSize, scaleFactor: CGFloat, rounded: Bool = true) -> Self {
|
|
|
|
var processor: ImageProcessor = DownsamplingImageProcessor(size: size)
|
|
|
|
|
|
|
|
if rounded {
|
|
|
|
processor = processor.append(another: RoundCornerImageProcessor(radius: .widthFraction(0.5)))
|
|
|
|
}
|
|
|
|
options.processor = processor
|
|
|
|
options.scaleFactor = scaleFactor
|
|
|
|
options.cacheOriginalImage = true
|
|
|
|
options.cacheSerializer = FormatIndicatedCacheSerializer.png
|
|
|
|
|
|
|
|
return self
|
|
|
|
}
|
|
|
|
|
|
|
|
func downsampled(dimension: CGFloat, scaleFactor: CGFloat, rounded: Bool = true) -> Self {
|
|
|
|
downsampled(size: CGSize(width: dimension, height: dimension), scaleFactor: scaleFactor, rounded: rounded)
|
|
|
|
}
|
|
|
|
}
|