Skip to content

Instantly share code, notes, and snippets.

@vzsg
Created October 18, 2016 19:28
Show Gist options
  • Save vzsg/964a307575fc2c534e90bd294b93ed8d to your computer and use it in GitHub Desktop.
Save vzsg/964a307575fc2c534e90bd294b93ed8d to your computer and use it in GitHub Desktop.
Kingfisher processor that replaces #FFFFFF with transparent color
import Foundation
import Kingfisher
import CoreImage
private let colorCubeData: [Float] = [
0, 0, 0, 1,
1, 0, 0, 1,
0, 1, 0, 1,
1, 1, 0, 1,
0, 0, 1, 1,
1, 0, 1, 1,
0, 1, 1, 1,
0, 0, 0, 0
]
private let cubeData = NSData(bytes: colorCubeData, length: colorCubeData.count * MemoryLayout<Float>.size)
struct WhiteToTransparentProcessor: CIImageProcessor {
let identifier = "com.ouroboros.WhiteToTransparent"
let filter = Filter { input in
guard let colorCube = CIFilter(name: "CIColorCube", withInputParameters: [
"inputCubeDimension": 2,
"inputCubeData": cubeData,
kCIInputImageKey: input]) else {
return nil
}
return colorCube.outputImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment