import PhotoEditorSDK
import UIKit
class PhotoAddFiltersFromAppBundleSwift: Example, PhotoEditViewControllerDelegate {
override func invokeExample() {
let photo = Photo(url: Bundle.main.url(forResource: "LA", withExtension: "jpg")!)
let customLUTFilter = LUTEffect(identifier: "custom_lut_filter", lutURL: Bundle.main.url(forResource: "custom_lut_invert", withExtension: "png"), displayName: "Invert", horizontalTileCount: 5, verticalTileCount: 5)
let customDuoToneFilter = DuoToneEffect(identifier: "custom_duotone_filter", lightColor: .yellow, darkColor: .blue, displayName: "Custom")
let configuration = Configuration { builder in
let assetCatalog = AssetCatalog.defaultItems
assetCatalog.effects.append(contentsOf: [customLUTFilter, customDuoToneFilter])
builder.assetCatalog = assetCatalog
let thumbnailURL = Bundle.main.url(forResource: "custom_filter_category", withExtension: "jpg")!
let thumbnailData = try? Data(contentsOf: thumbnailURL)
let thumbnail = UIImage(data: thumbnailData!)
let customFilterGroup = Group(identifier: "custom_filter_category", displayName: "Custom", thumbnail: thumbnail, memberIdentifiers: ["custom_lut_filter"])
builder.configureFilterToolController { options in
options.filterGroups.append(customFilterGroup)
}
}
let photoEditViewController = PhotoEditViewController(photoAsset: photo, configuration: configuration)
photoEditViewController.delegate = self
photoEditViewController.modalPresentationStyle = .fullScreen
presentingViewController?.present(photoEditViewController, animated: true, completion: nil)
}
func photoEditViewControllerShouldStart(_ photoEditViewController: PhotoEditViewController, task: PhotoEditorTask) -> Bool {
true
}
func photoEditViewControllerDidFinish(_ photoEditViewController: PhotoEditViewController, result: PhotoEditorResult) {
presentingViewController?.dismiss(animated: true, completion: nil)
}
func photoEditViewControllerDidFail(_ photoEditViewController: PhotoEditViewController, error: PhotoEditorError) {
print(error.localizedDescription)
presentingViewController?.dismiss(animated: true, completion: nil)
}
func photoEditViewControllerDidCancel(_ photoEditViewController: PhotoEditViewController) {
presentingViewController?.dismiss(animated: true, completion: nil)
}
}