Skip to content

Commit ad24d59

Browse files
committed
deepimage init
1 parent 1910739 commit ad24d59

File tree

5 files changed

+238
-6
lines changed

5 files changed

+238
-6
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import deepimage from "../../deepimage.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "deepimage-auto-enhance",
6+
name: "Auto Enhance Image",
7+
description: "Improves the provided image. [See the documentation](https://documentation.deep-image.ai/image-processing/auto-enhance)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
deepimage,
12+
image: {
13+
propDefinition: [
14+
deepimage,
15+
"image",
16+
],
17+
},
18+
},
19+
async run({ $ }) {
20+
const response = await this.deepimage.improveImage({
21+
image: this.image,
22+
});
23+
24+
$.export("$summary", "Successfully enhanced the image.");
25+
return response;
26+
},
27+
};
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import deepimage from "../../deepimage.app.mjs";
2+
3+
export default {
4+
key: "deepimage-remove-background",
5+
name: "Remove Background",
6+
description: "Removes the background from the provided image using DeepImage. [See the documentation](https://documentation.deep-image.ai/quick-start)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
deepimage,
11+
image: {
12+
propDefinition: [
13+
deepimage,
14+
"image",
15+
],
16+
},
17+
backgroundColor: {
18+
propDefinition: [
19+
deepimage,
20+
"backgroundColor",
21+
],
22+
},
23+
cropType: {
24+
propDefinition: [
25+
deepimage,
26+
"cropType",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.deepimage.removeBackground({
32+
image: this.image,
33+
backgroundColor: this.backgroundColor,
34+
cropType: this.cropType,
35+
});
36+
37+
$.export("$summary", "Background removal successful");
38+
return response;
39+
},
40+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import deepimage from "../../deepimage.app.mjs";
2+
3+
export default {
4+
key: "deepimage-upscale",
5+
name: "Upscale Image",
6+
description: "Upscales the provided image using Deep Image. [See the documentation](https://documentation.deep-image.ai/)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
deepimage,
11+
image: {
12+
propDefinition: [
13+
deepimage,
14+
"image",
15+
],
16+
},
17+
upscaleMultiplier: {
18+
propDefinition: [
19+
deepimage,
20+
"upscaleMultiplier",
21+
],
22+
},
23+
generativeUpscale: {
24+
propDefinition: [
25+
deepimage,
26+
"generativeUpscale",
27+
],
28+
optional: true,
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.deepimage.upscaleImage({
33+
image: this.image,
34+
upscaleMultiplier: this.upscaleMultiplier,
35+
generativeUpscale: this.generativeUpscale,
36+
});
37+
38+
$.export("$summary", "Successfully upscaled the image");
39+
return response;
40+
},
41+
};
Lines changed: 129 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,135 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "deepimage",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
image: {
8+
type: "string",
9+
label: "Image URL",
10+
description: "The URL of the image to process",
11+
},
12+
backgroundColor: {
13+
type: "string",
14+
label: "Background Color",
15+
description: "The background color for the image, either 'white' or 'transparent'.",
16+
options: [
17+
{
18+
label: "White",
19+
value: "white",
20+
},
21+
{
22+
label: "Transparent",
23+
value: "transparent",
24+
},
25+
],
26+
},
27+
cropType: {
28+
type: "string",
29+
label: "Crop Type",
30+
description: "The crop type for background removal.",
31+
optional: true,
32+
options: [
33+
{
34+
label: "Center",
35+
value: "center",
36+
},
37+
{
38+
label: "Item",
39+
value: "item",
40+
},
41+
{
42+
label: "Content",
43+
value: "content",
44+
},
45+
{
46+
label: "Cover",
47+
value: "cover",
48+
},
49+
{
50+
label: "Canvas",
51+
value: "canvas",
52+
},
53+
{
54+
label: "Bounds",
55+
value: "bounds",
56+
},
57+
],
58+
},
59+
upscaleMultiplier: {
60+
type: "integer",
61+
label: "Upscale Multiplier",
62+
description: "The factor by which to upscale the image.",
63+
},
64+
generativeUpscale: {
65+
type: "boolean",
66+
label: "Generative Upscale",
67+
description: "Whether to use generative upscale.",
68+
optional: true,
69+
},
70+
},
571
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
72+
_baseUrl() {
73+
return "https://deep-image.ai/rest_api";
74+
},
75+
async _makeRequest(opts = {}) {
76+
const {
77+
$ = this, method = "POST", path = "/", headers, ...otherOpts
78+
} = opts;
79+
return axios($, {
80+
...otherOpts,
81+
method,
82+
url: this._baseUrl() + path,
83+
headers: {
84+
...headers,
85+
"X-API-Key": this.$auth.api_key,
86+
"Content-Type": "application/json",
87+
},
88+
});
89+
},
90+
async improveImage({
91+
image, ...opts
92+
}) {
93+
return this._makeRequest({
94+
data: {
95+
url: image,
96+
preset: "auto_enhance",
97+
...opts,
98+
},
99+
});
100+
},
101+
async removeBackground({
102+
image, backgroundColor, cropType, ...opts
103+
}) {
104+
return this._makeRequest({
105+
data: {
106+
url: image,
107+
background: {
108+
remove: "auto",
109+
color: backgroundColor === "white"
110+
? "#FFFFFF"
111+
: "transparent",
112+
crop: cropType || "center",
113+
},
114+
...opts,
115+
},
116+
});
117+
},
118+
async upscaleImage({
119+
image, upscaleMultiplier, generativeUpscale, ...opts
120+
}) {
121+
return this._makeRequest({
122+
data: {
123+
url: image,
124+
upscale_parameters: {
125+
type: generativeUpscale
126+
? "text_x4"
127+
: "v1",
128+
},
129+
width: upscaleMultiplier * 1000,
130+
...opts,
131+
},
132+
});
9133
},
10134
},
11-
};
135+
};

components/deepimage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)