فهرست منبع

Revert to cache correct image version

onevcat 8 سال پیش
والد
کامیت
5d678292e9
1فایلهای تغییر یافته به همراه11 افزوده شده و 2 حذف شده
  1. 11 2
      Sources/CacheSerializer.swift

+ 11 - 2
Sources/CacheSerializer.swift

@@ -63,8 +63,17 @@ public struct DefaultCacheSerializer: CacheSerializer {
     private init() {}
     
     public func data(with image: Image, original: Data?) -> Data? {
-        // If original data is provided, just use it.
-        return original ?? image.kf.normalized.kf.pngRepresentation()
+        let imageFormat = original?.kf.imageFormat ?? .unknown
+
+        let data: Data?
+        switch imageFormat {
+        case .PNG: data = image.kf.pngRepresentation()
+        case .JPEG: data = image.kf.jpegRepresentation(compressionQuality: 1.0)
+        case .GIF: data = image.kf.gifRepresentation()
+        case .unknown: data = original ?? image.kf.normalized.kf.pngRepresentation()
+        }
+
+        return data
     }
     
     public func image(with data: Data, options: KingfisherOptionsInfo?) -> Image? {