metatext/Extensions/KingfisherOptionsInfo+Extensions.swift

31 lines
1.1 KiB
Swift
Raw Normal View History

2020-08-05 11:48:50 +00:00
// Copyright © 2020 Metabolist. All rights reserved.
import struct Kingfisher.DownsamplingImageProcessor
import struct Kingfisher.FormatIndicatedCacheSerializer
2020-09-05 02:31:43 +00:00
import protocol Kingfisher.ImageProcessor
import struct Kingfisher.KingfisherOptionsInfo
import struct Kingfisher.RoundCornerImageProcessor
import KingfisherSwiftUI
import SwiftUI
2020-08-05 11:48:50 +00: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)
}
}