Language
From App Bundle
PhotoEditor SDK supports adding custom overlays from the app bundle. In this example, we add the custom IMG.LY "Grain" overlay.
Load overlay from bundle#
For the custom overlay we construct an Overlay
object providing the local resource URL and a display name for our overlay.
In addition we set the initial blend mode to hardLight
, an exhaustive list of available blend modes can be found in the API docs.
Add overlay to asset catalog#
In order to add the new overlay to our asset catalog, we first add the default items and then append our overlay to the overlays
array.
import PhotoEditorSDKimport UIKitclass PhotoAddOverlaysFromAppBundleSwift: Example, PhotoEditViewControllerDelegate {override func invokeExample() {// Create a `Photo` from a URL to an image in the app bundle.let photo = Photo(url: Bundle.main.url(forResource: "LA", withExtension: "jpg")!)// Create a custom `Overlay`.let customOverlay = Overlay(identifier: "imgly_overlay_grain", displayName: "Grain", url: Bundle.main.url(forResource: "imgly_overlay_grain", withExtension: "jpg"), thumbnailURL: nil, initialBlendMode: .hardLight)// Create a `Configuration` object.let configuration = Configuration { builder in// In this example we are using the default assets for the asset catalog as a base.// However, you can also create an empty catalog as well which only contains your// custom assets.let assetCatalog = AssetCatalog.defaultItems// Add the custom overlay to the asset catalog.assetCatalog.overlays.append(customOverlay)// Use the new asset catalog for the configuration.builder.assetCatalog = assetCatalog}// Create and present the photo editor. Make this class the delegate of it to handle export and cancelation.let photoEditViewController = PhotoEditViewController(photoAsset: photo, configuration: configuration)photoEditViewController.delegate = selfphotoEditViewController.modalPresentationStyle = .fullScreenpresentingViewController?.present(photoEditViewController, animated: true, completion: nil)}// MARK: - PhotoEditViewControllerDelegatefunc photoEditViewControllerShouldStart(_ photoEditViewController: PhotoEditViewController, task: PhotoEditorTask) -> Bool {// Implementing this method is optional. You can perform additional validation and interrupt the process by returning `false`.true}func photoEditViewControllerDidFinish(_ photoEditViewController: PhotoEditViewController, result: PhotoEditorResult) {// The image has been exported successfully and is passed as an `Data` object in the `result.output.data`.// To create an `UIImage` from the output, use `UIImage(data:)`.// See other examples about how to save the resulting image.presentingViewController?.dismiss(animated: true, completion: nil)}func photoEditViewControllerDidFail(_ photoEditViewController: PhotoEditViewController, error: PhotoEditorError) {// There was an error generating the photo.print(error.localizedDescription)// Dismissing the editor.presentingViewController?.dismiss(animated: true, completion: nil)}func photoEditViewControllerDidCancel(_ photoEditViewController: PhotoEditViewController) {// The user tapped on the cancel button within the editor. Dismissing the editor.presentingViewController?.dismiss(animated: true, completion: nil)}}