UNPKG

@jacobjmc/react-native-background-remover

Version:

Enhanced React Native package for removing backgrounds from images containing people, objects, animals, and more using Apple's Vision framework

42 lines (39 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeBackground = removeBackground; var _reactNative = require("react-native"); const LINKING_ERROR = `The package 'react-native-background-remover' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; // @ts-ignore const isTurboModuleEnabled = global.__turboModuleProxy != null; const BackgroundRemoverModule = isTurboModuleEnabled ? require('./NativeBackgroundRemover').default : _reactNative.NativeModules.BackgroundRemover; const BackgroundRemover = BackgroundRemoverModule ? BackgroundRemoverModule : new Proxy({}, { get() { throw new Error(LINKING_ERROR); } }); /** * Removes the background from an image. * Note: This method isn't usable on iOS simulators, you need to have a real device. * @returns The URI of the image with the background removed. * @returns the original URI if you are using an iOS simulator. * @throws Error if the iOS device is not at least on iOS 15.0. * @throws Error if the image could not be processed for an unknown reason. */ async function removeBackground(imageURI) { try { const result = await BackgroundRemover.removeBackground(imageURI); return result; } catch (error) { if (error instanceof Error && error.message === 'SimulatorError') { console.warn('[ReactNativeBackgroundRemover]: You need to have a real device. This feature is not available on simulators. Returning the original image URI.'); return imageURI; } throw error; } } //# sourceMappingURL=index.js.map