Skip to content

Photoroom/PhotoRoomKit-Swift

Repository files navigation

PhotoRoomKit

Version Carthage Compatible License Platform Swift

⚠️ Important – Deprecated ⚠️

Please note that PhotoRoomKit has been deprecated.

For an up-to-date code sample, please check out: https://github.com/PhotoRoom/api-code-samples/

Description

PhotoRoomKit is a fast background removal API. Power your app with the background removal technology used by millions of sellers every month.

Installation

PhotoRoomKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'PhotoRoomKit'

PhotoRoomKit is also available through Carthage. To install just write into your Cartfile:

github "PhotoRoom/PhotoRoomKit"

PhotoRoomKit can also be installed manually. Just download and drop Sources folders in your project.

Usage

First you will need an API Key, go to our API website to get your own PhotoRoom key.

Then, you can either use the provided PhotoRoomViewController, or use the API wrapper

PhotoRoomViewController

Just present PhotoRoomViewController and handle the callback

func removeBackground(_ originalImage: UIImage) {
    let controller = PhotoRoomViewController(image: originalImage,
                                                       apiKey: 'YOUR_API_KEY') { [weak self] image in
        self?.onImageEdited(image)

    }
    present(controller, animated: true)
}

func onImageEdited(_ editedImage: UIImage) {
    // Handle your segmented image
}

When using the built-in view controller, Photoroom attribution is done for you, no need for extra work.

API wrapper

You can also use the API wrapper directly.

let segmentationService = SegmentationService(apiKey: apiKey)
segmentationService.segment(image: originalImage) { (image, error) in
    DispatchQueue.main.async {
        if let error = error {
            // An error occured
        }
        guard let image = image else {
            // No image returned
            return
        }
        // All good
    }
}

⚠️ If you use the API wrapper, you'll need to provide correct attribution according to our API guideline.

Author

PhotoRoom, [email protected]

Contributing

We would love you to contribute to PhotoRoomKit, check the CONTRIBUTING file for more info.

License

PhotoRoomKit is available under the MIT license. See the LICENSE file for more info.