Skip to content

Commit ec84090

Browse files
committed
Updated .background remove to actually work
1 parent 79054e8 commit ec84090

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

src/api/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ export async function imageOverlayShutterstock(
687687

688688
export async function imageToolsBackgroundRemove(
689689
context: RequestContext,
690-
options: RestOptions.ImageBaseOptions,
690+
options: RestOptions.ImageBackgroundRemoveOptions,
691691
) {
692692
return raw.imageToolsBackgroundRemove(context, options);
693693
}

src/api/raw.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,9 +1392,10 @@ export async function imageOverlayShutterstock(
13921392

13931393
export async function imageToolsBackgroundRemove(
13941394
context: RequestContext,
1395-
options: RestOptions.ImageBaseOptions,
1395+
options: RestOptions.ImageBackgroundRemoveOptions,
13961396
): Promise<Response> {
13971397
const query = {
1398+
model: options.model,
13981399
url: options.url,
13991400
};
14001401
return request(context, {

src/api/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ export namespace RestOptions {
136136
url: string,
137137
}
138138

139+
export interface ImageBackgroundRemoveOptions extends ImageBaseOptions {
140+
model?: string,
141+
}
142+
139143
export interface ImageCreateTombstone {
140144
line1?: string,
141145
line2?: string,

src/commands/prefixed/image/background.remove.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { Command, CommandClient } from 'detritus-client';
22

33
import { imageToolsBackgroundRemove } from '../../../api';
4-
import { CommandTypes } from '../../../constants';
4+
import { CommandTypes, ImageBackgroundRemovalModels } from '../../../constants';
55
import { imageReply } from '../../../utils';
66

77
import { BaseImageCommand } from '../basecommand';
88

99

1010
export interface CommandArgsBefore {
11+
model?: string,
1112
url?: null | string,
1213
}
1314

1415
export interface CommandArgs {
16+
model?: string,
1517
url: string,
1618
}
1719

@@ -23,14 +25,18 @@ export default class GrayscaleCommand extends BaseImageCommand<CommandArgs> {
2325
name: COMMAND_NAME,
2426

2527
aliases: ['background rm', 'bg remove', 'bg rm'],
28+
args: [
29+
{name: 'model', choices: Object.values(ImageBackgroundRemovalModels), help: `Must be one of: (${Object.values(ImageBackgroundRemovalModels).join(', ')})`},
30+
],
2631
metadata: {
2732
description: 'Remove the background of an image',
2833
examples: [
2934
COMMAND_NAME,
3035
`${COMMAND_NAME} notsobot`,
36+
`${COMMAND_NAME} notsobot -model U2NETP`,
3137
],
3238
type: CommandTypes.IMAGE,
33-
usage: '?<emoji,user:id|mention|name,url>',
39+
usage: '?<emoji,user:id|mention|name,url> (-model <ImageBackgroundRemovalModels>)',
3440
},
3541
});
3642
}

src/constants.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,13 @@ export enum GuildPremiumTypes {
482482
};
483483

484484

485+
export enum ImageBackgroundRemovalModels {
486+
ALPHA_MATTING = 'ALPHA_MATTING',
487+
U2NET = 'U2NET',
488+
U2NETP = 'U2NETP',
489+
U2NET_HUMAN_SEG = 'U2NET_HUMAN_SEG',
490+
}
491+
485492

486493
export enum ImageEyeTypes {
487494
BIG = 'BIG',

0 commit comments

Comments
 (0)