From 8075b65e1415f3346ba97f3180b340cea76112e4 Mon Sep 17 00:00:00 2001 From: Mohammed Zaher Date: Thu, 16 Nov 2023 15:39:46 +0000 Subject: [PATCH] feat(removebg): Add `Remove image background` action --- .../src/apps/removebg/actions/index.ts | 3 + .../actions/remove-image-background/index.ts | 81 +++++++++++++++++++ packages/backend/src/apps/removebg/index.ts | 2 + 3 files changed, 86 insertions(+) create mode 100644 packages/backend/src/apps/removebg/actions/index.ts create mode 100644 packages/backend/src/apps/removebg/actions/remove-image-background/index.ts diff --git a/packages/backend/src/apps/removebg/actions/index.ts b/packages/backend/src/apps/removebg/actions/index.ts new file mode 100644 index 00000000..ce680432 --- /dev/null +++ b/packages/backend/src/apps/removebg/actions/index.ts @@ -0,0 +1,3 @@ +import removeImageBackground from './remove-image-background'; + +export default [removeImageBackground]; \ No newline at end of file diff --git a/packages/backend/src/apps/removebg/actions/remove-image-background/index.ts b/packages/backend/src/apps/removebg/actions/remove-image-background/index.ts new file mode 100644 index 00000000..9db4ef29 --- /dev/null +++ b/packages/backend/src/apps/removebg/actions/remove-image-background/index.ts @@ -0,0 +1,81 @@ +import defineAction from '../../../../helpers/define-action'; + +export default defineAction({ + name: 'Remove Image Background', + key: 'removeImageBackground', + description: + 'Removes the background of an image.', + arguments: [ + { + label: 'Image file', + key: 'imageFile', + type: 'string' as const, + required: true, + variables: true, + description: 'Provide a JPG or PNG file, up to 12 MB (see remove.bg/supported-images)', + }, + { + label: 'Size', + key: 'size', + type: 'dropdown' as const, + required: true, + value: 'auto', + options: [ + { label: 'Auto', value: 'auto' }, + { label: 'Preview (up to 0.25 megapixels)', value: 'preview' }, + { label: 'Full (up to 10 megapixels)', value: 'full' }, + ] + }, + { + label: 'Add background color', + key: 'bgColor', + type: 'string' as const, + description: 'Can be a hex color code (e.g. 81d4fa, fff) or a color name (e.g. green)', + required: false, + }, + { + label: 'Add background image URL', + key: 'bgImage', + type: 'string' as const, + required: false, + }, + { + label: 'Output image format', + key: 'outputFormat', + type: 'dropdown' as const, + description: 'Note: Use PNG to preserve transparency', + required: true, + value: 'auto', + options: [ + { label: 'Auto', value: 'auto' }, + { label: 'PNG', value: 'png' }, + { label: 'JPG', value: 'jpg' }, + { label: 'ZIP', value: 'zip'} + ] + } + ], + async run($) { + const imageFile = $.step.parameters.imageFile as string; + const size = $.step.parameters.size as string; + const bgColor = $.step.parameters.bgColor as string; + const bgImage = $.step.parameters.bgImage as string; + const outputFormat = $.step.parameters.outputFormat as string; + + const body = JSON.stringify({ + image_file_b64: imageFile, + size: size, + bg_Color: bgColor, + bg_image_url: bgImage, + format: outputFormat + }); + + const response = await $.http.post('/removebg', body, { + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + }); + + $.setActionItem({ raw: response.data }); + } +}) \ No newline at end of file diff --git a/packages/backend/src/apps/removebg/index.ts b/packages/backend/src/apps/removebg/index.ts index c9827811..4ac8f5e7 100644 --- a/packages/backend/src/apps/removebg/index.ts +++ b/packages/backend/src/apps/removebg/index.ts @@ -1,6 +1,7 @@ import defineApp from '../../helpers/define-app'; import addAuthHeader from './common/add-auth-header'; import auth from './auth'; +import actions from './actions'; export default defineApp({ name: 'Remove.bg', @@ -13,4 +14,5 @@ export default defineApp({ primaryColor: '55636c', beforeRequest: [addAuthHeader], auth, + actions, });