|
@@ -206,7 +206,7 @@ extension Kingfisher where Base: Image {
|
|
|
|
|
|
|
|
// MARK: - Create images from data
|
|
// MARK: - Create images from data
|
|
|
extension Kingfisher where Base: Image {
|
|
extension Kingfisher where Base: Image {
|
|
|
- static func animated(with data: Data, scale: CGFloat = 1.0, duration: TimeInterval = 0.0, preloadAll: Bool, onlyFirstFrame: Bool = false) -> Image? {
|
|
|
|
|
|
|
+ public static func animated(with data: Data, scale: CGFloat = 1.0, duration: TimeInterval = 0.0, preloadAll: Bool, onlyFirstFrame: Bool = false) -> Image? {
|
|
|
|
|
|
|
|
func decode(from imageSource: CGImageSource, for options: NSDictionary) -> ([Image], TimeInterval)? {
|
|
func decode(from imageSource: CGImageSource, for options: NSDictionary) -> ([Image], TimeInterval)? {
|
|
|
|
|
|
|
@@ -293,7 +293,7 @@ extension Kingfisher where Base: Image {
|
|
|
#endif
|
|
#endif
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- static func image(data: Data, scale: CGFloat, preloadAllAnimationData: Bool, onlyFirstFrame: Bool) -> Image? {
|
|
|
|
|
|
|
+ public static func image(data: Data, scale: CGFloat, preloadAllAnimationData: Bool, onlyFirstFrame: Bool) -> Image? {
|
|
|
var image: Image?
|
|
var image: Image?
|
|
|
|
|
|
|
|
#if os(macOS)
|
|
#if os(macOS)
|
|
@@ -708,11 +708,11 @@ extension Kingfisher where Base: Image {
|
|
|
|
|
|
|
|
// MARK: - Decode
|
|
// MARK: - Decode
|
|
|
extension Kingfisher where Base: Image {
|
|
extension Kingfisher where Base: Image {
|
|
|
- var decoded: Image {
|
|
|
|
|
|
|
+ public var decoded: Image {
|
|
|
return decoded(scale: scale)
|
|
return decoded(scale: scale)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- func decoded(scale: CGFloat) -> Image {
|
|
|
|
|
|
|
+ public func decoded(scale: CGFloat) -> Image {
|
|
|
// prevent animated image (GIF) lose it's images
|
|
// prevent animated image (GIF) lose it's images
|
|
|
#if os(iOS)
|
|
#if os(iOS)
|
|
|
if imageSource != nil { return base }
|
|
if imageSource != nil { return base }
|
|
@@ -756,7 +756,7 @@ private struct ImageHeaderData {
|
|
|
static var GIF: [UInt8] = [0x47, 0x49, 0x46]
|
|
static var GIF: [UInt8] = [0x47, 0x49, 0x46]
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-enum ImageFormat {
|
|
|
|
|
|
|
+public enum ImageFormat {
|
|
|
case unknown, PNG, JPEG, GIF
|
|
case unknown, PNG, JPEG, GIF
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -777,7 +777,7 @@ extension Data: KingfisherCompatible {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
extension DataProxy {
|
|
extension DataProxy {
|
|
|
- var imageFormat: ImageFormat {
|
|
|
|
|
|
|
+ public var imageFormat: ImageFormat {
|
|
|
var buffer = [UInt8](repeating: 0, count: 8)
|
|
var buffer = [UInt8](repeating: 0, count: 8)
|
|
|
(base as NSData).getBytes(&buffer, length: 8)
|
|
(base as NSData).getBytes(&buffer, length: 8)
|
|
|
if buffer == ImageHeaderData.PNG {
|
|
if buffer == ImageHeaderData.PNG {
|
|
@@ -813,14 +813,26 @@ extension CGSize: KingfisherCompatible {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
extension CGSizeProxy {
|
|
extension CGSizeProxy {
|
|
|
- func constrained(_ size: CGSize) -> CGSize {
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public func resize(to size: CGSize, for contentMode: ContentMode) -> CGSize {
|
|
|
|
|
+ switch contentMode {
|
|
|
|
|
+ case .aspectFit:
|
|
|
|
|
+ return constrained(size)
|
|
|
|
|
+ case .aspectFill:
|
|
|
|
|
+ return filling(size)
|
|
|
|
|
+ default:
|
|
|
|
|
+ return self.base
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public func constrained(_ size: CGSize) -> CGSize {
|
|
|
let aspectWidth = round(aspectRatio * size.height)
|
|
let aspectWidth = round(aspectRatio * size.height)
|
|
|
let aspectHeight = round(size.width / aspectRatio)
|
|
let aspectHeight = round(size.width / aspectRatio)
|
|
|
|
|
|
|
|
return aspectWidth > size.width ? CGSize(width: size.width, height: aspectHeight) : CGSize(width: aspectWidth, height: size.height)
|
|
return aspectWidth > size.width ? CGSize(width: size.width, height: aspectHeight) : CGSize(width: aspectWidth, height: size.height)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- func filling(_ size: CGSize) -> CGSize {
|
|
|
|
|
|
|
+ public func filling(_ size: CGSize) -> CGSize {
|
|
|
let aspectWidth = round(aspectRatio * size.height)
|
|
let aspectWidth = round(aspectRatio * size.height)
|
|
|
let aspectHeight = round(size.width / aspectRatio)
|
|
let aspectHeight = round(size.width / aspectRatio)
|
|
|
|
|
|
|
@@ -832,7 +844,7 @@ extension CGSizeProxy {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- func constrainedRect(for size: CGSize, anchor: CGPoint) -> CGRect {
|
|
|
|
|
|
|
+ public func constrainedRect(for size: CGSize, anchor: CGPoint) -> CGRect {
|
|
|
|
|
|
|
|
let unifiedAnchor = CGPoint(x: anchor.x.clamped(to: 0.0...1.0),
|
|
let unifiedAnchor = CGPoint(x: anchor.x.clamped(to: 0.0...1.0),
|
|
|
y: anchor.y.clamped(to: 0.0...1.0))
|
|
y: anchor.y.clamped(to: 0.0...1.0))
|