diff --git a/Modules/RSCore/Sources/RSCore/Shared/RSImage.swift b/Modules/RSCore/Sources/RSCore/Shared/RSImage.swift index 7e8e5caf8..aa7e4220b 100644 --- a/Modules/RSCore/Sources/RSCore/Shared/RSImage.swift +++ b/Modules/RSCore/Sources/RSCore/Shared/RSImage.swift @@ -83,16 +83,25 @@ public extension RSImage { } #endif +#if os(macOS) + /// Returns data as PNG. May be nil in some circumstances. + func pngData() -> Data? { + guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else { + return nil + } + let bitmapRep = NSBitmapImageRep(cgImage: cgImage) + return bitmapRep.representation(using: .png, properties: [:]) + } +#endif + /// Returns a data representation of the image. - /// - /// The resultant data is TIFF data on macOS, and PNG data on iOS. - /// - Returns: Data representing the image. + /// - Returns: Image data. Normally PNG, though in rare cases it might TIFF on macOS. func dataRepresentation() -> Data? { - #if os(macOS) - return tiffRepresentation - #else - return pngData() - #endif +#if os(macOS) + pngData() ?? tiffRepresentation +#else + return pngData() +#endif } /// Asynchronously initializes an image from data. diff --git a/Shared/Extensions/ArticleUtilities.swift b/Shared/Extensions/ArticleUtilities.swift index 1a526f5e0..2deaa3f52 100644 --- a/Shared/Extensions/ArticleUtilities.swift +++ b/Shared/Extensions/ArticleUtilities.swift @@ -126,11 +126,7 @@ extension Article { let fm = FileManager.default var path = fm.urls(for: .cachesDirectory, in: .userDomainMask)[0] let feedID = webFeed.webFeedID.replacingOccurrences(of: "/", with: "_") - #if os(macOS) - path.appendPathComponent(feedID + "_smallIcon.tiff") - #else path.appendPathComponent(feedID + "_smallIcon.png") - #endif fm.createFile(atPath: path.path, contents: image.image.dataRepresentation()!, attributes: nil) return path } else {