123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import Foundation
- public protocol ImageModifier {
-
-
-
-
-
-
-
-
-
- func modify(_ image: KFCrossPlatformImage) -> KFCrossPlatformImage
- }
- public struct AnyImageModifier: ImageModifier {
-
-
- let block: (KFCrossPlatformImage) throws -> KFCrossPlatformImage
-
- public init(modify: @escaping (KFCrossPlatformImage) throws -> KFCrossPlatformImage) {
- block = modify
- }
-
- public func modify(_ image: KFCrossPlatformImage) -> KFCrossPlatformImage {
- return (try? block(image)) ?? image
- }
- }
- #if os(iOS) || os(tvOS) || os(watchOS)
- import UIKit
- public struct RenderingModeImageModifier: ImageModifier {
-
- public let renderingMode: UIImage.RenderingMode
-
-
-
- public init(renderingMode: UIImage.RenderingMode = .automatic) {
- self.renderingMode = renderingMode
- }
-
- public func modify(_ image: KFCrossPlatformImage) -> KFCrossPlatformImage {
- return image.withRenderingMode(renderingMode)
- }
- }
- public struct FlipsForRightToLeftLayoutDirectionImageModifier: ImageModifier {
-
- public init() {}
-
- public func modify(_ image: KFCrossPlatformImage) -> KFCrossPlatformImage {
- return image.imageFlippedForRightToLeftLayoutDirection()
- }
- }
- public struct AlignmentRectInsetsImageModifier: ImageModifier {
-
- public let alignmentInsets: UIEdgeInsets
-
- public init(alignmentInsets: UIEdgeInsets) {
- self.alignmentInsets = alignmentInsets
- }
-
- public func modify(_ image: KFCrossPlatformImage) -> KFCrossPlatformImage {
- return image.withAlignmentRectInsets(alignmentInsets)
- }
- }
- #endif
|