Browse Source

Change some functions to public type

fengyunjue 7 years ago
parent
commit
cc553b7ecc
2 changed files with 22 additions and 10 deletions
  1. 21 9
      Sources/Image.swift
  2. 1 1
      Sources/String+MD5.swift

+ 21 - 9
Sources/Image.swift

@@ -206,7 +206,7 @@ extension Kingfisher where Base: Image {
 
 // MARK: - Create images from data
 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)? {
             
@@ -293,7 +293,7 @@ extension Kingfisher where Base: Image {
         #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?
 
         #if os(macOS)
@@ -708,11 +708,11 @@ extension Kingfisher where Base: Image {
 
 // MARK: - Decode
 extension Kingfisher where Base: Image {
-    var decoded: Image {
+    public var decoded: Image {
         return decoded(scale: scale)
     }
     
-    func decoded(scale: CGFloat) -> Image {
+    public func decoded(scale: CGFloat) -> Image {
         // prevent animated image (GIF) lose it's images
         #if os(iOS)
             if imageSource != nil { return base }
@@ -756,7 +756,7 @@ private struct ImageHeaderData {
     static var GIF: [UInt8] = [0x47, 0x49, 0x46]
 }
 
-enum ImageFormat {
+public enum ImageFormat {
     case unknown, PNG, JPEG, GIF
 }
 
@@ -777,7 +777,7 @@ extension Data: KingfisherCompatible {
 }
 
 extension DataProxy {
-    var imageFormat: ImageFormat {
+    public var imageFormat: ImageFormat {
         var buffer = [UInt8](repeating: 0, count: 8)
         (base as NSData).getBytes(&buffer, length: 8)
         if buffer == ImageHeaderData.PNG {
@@ -813,14 +813,26 @@ extension CGSize: KingfisherCompatible {
 }
 
 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 aspectHeight = round(size.width / aspectRatio)
 
         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 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),
                                     y: anchor.y.clamped(to: 0.0...1.0))

+ 1 - 1
Sources/String+MD5.swift

@@ -24,7 +24,7 @@ import Foundation
 extension String: KingfisherCompatible { }
 
 extension Kingfisher where Base == String {
-    var md5: String {
+    public var md5: String {
         if let data = base.data(using: .utf8, allowLossyConversion: true) {
 
             let message = data.withUnsafeBytes { bytes -> [UInt8] in