Skip to content

Commit b752ef0

Browse files
authored
New Components - change_photos (#15107)
* change_photos init * new component * pnpm-lock.yaml * update
1 parent 08fa304 commit b752ef0

File tree

4 files changed

+189
-6
lines changed

4 files changed

+189
-6
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import changePhotos from "../../change_photos.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
4+
export default {
5+
key: "change_photos-transform-image",
6+
name: "Transform Image",
7+
description: "Transforms an image with various effects and optimizations. [See the documentation](https://www.change.photos/api-docs)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
changePhotos,
12+
imageUrl: {
13+
type: "string",
14+
label: "Image URL",
15+
description: "URL of the image to transform",
16+
},
17+
width: {
18+
type: "integer",
19+
label: "Width",
20+
description: "Desired width in pixels of the output image",
21+
optional: true,
22+
},
23+
height: {
24+
type: "integer",
25+
label: "Height",
26+
description: "Desired height in pixels of the output image",
27+
optional: true,
28+
},
29+
format: {
30+
type: "string",
31+
label: "Format",
32+
description: "Output image format. Default: `jpeg`",
33+
options: [
34+
"jpeg",
35+
"png",
36+
"webp",
37+
],
38+
optional: true,
39+
},
40+
quality: {
41+
type: "integer",
42+
label: "Quality",
43+
description: "Output image quality. Must be between `1` and `100`. Default: `80`",
44+
optional: true,
45+
},
46+
fit: {
47+
type: "string",
48+
label: "Fit",
49+
description: "How the image should fit within the dimensions. Default: `contain`",
50+
options: [
51+
"contain",
52+
"cover",
53+
"fill",
54+
"inside",
55+
"outside",
56+
],
57+
optional: true,
58+
},
59+
flip: {
60+
type: "boolean",
61+
label: "Flip",
62+
description: "Flip the image vertically",
63+
optional: true,
64+
},
65+
flop: {
66+
type: "boolean",
67+
label: "Flop",
68+
description: "Flip the image horizontally",
69+
optional: true,
70+
},
71+
rotate: {
72+
type: "integer",
73+
label: "Rotate",
74+
description: "Rotation angle in degrees. Must be between `-360` and `360`. Default: `0`",
75+
optional: true,
76+
},
77+
grayscale: {
78+
type: "boolean",
79+
label: "Grayscale",
80+
description: "Convert image to grayscale",
81+
optional: true,
82+
},
83+
blur: {
84+
type: "string",
85+
label: "Blur",
86+
description: "Gaussian blur sigma value. Must be between `0.3` and `1000`.",
87+
optional: true,
88+
},
89+
sharpen: {
90+
type: "boolean",
91+
label: "Sharpen",
92+
description: "Apply sharpening effect",
93+
optional: true,
94+
},
95+
compress: {
96+
type: "boolean",
97+
label: "Compress",
98+
description: "Apply additional compression",
99+
optional: true,
100+
},
101+
tintRedComponent: {
102+
type: "string",
103+
label: "Tint - Red Component",
104+
description: "Red Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
105+
optional: true,
106+
},
107+
tintGreenComponent: {
108+
type: "string",
109+
label: "Tint - Green Component",
110+
description: "Green Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
111+
optional: true,
112+
},
113+
tintBlueComponent: {
114+
type: "string",
115+
label: "Tint - Blue Component",
116+
description: "Blue Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
117+
optional: true,
118+
},
119+
},
120+
async run({ $ }) {
121+
if (
122+
(this.tintRedComponent || this.tintGreenComponent || this.tintBlueComponent)
123+
&& !(this.tintRedComponent && this.tintGreenComponent && this.tintBlueComponent)
124+
) {
125+
throw new ConfigurationError("Must specify Red, Green, and Blue RGB components to apply tint");
126+
}
127+
128+
const response = await this.changePhotos.transformImage({
129+
$,
130+
data: {
131+
url: this.imageUrl,
132+
width: this.width,
133+
height: this.height,
134+
format: this.format,
135+
quality: this.quality,
136+
fit: this.fit,
137+
flip: this.flip,
138+
flop: this.flop,
139+
rotate: this.rotate,
140+
grayscale: this.grayscale,
141+
blur: this.blur && +this.blur,
142+
sharpen: this.sharpen,
143+
compress: this.compress,
144+
tint: this.tintRedComponent && {
145+
r: +this.tintRedComponent,
146+
g: +this.tintGreenComponent,
147+
b: +this.tintBlueComponent,
148+
},
149+
},
150+
});
151+
152+
$.export("$summary", "Image transformed successfully");
153+
return response;
154+
},
155+
};
Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "change_photos",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_baseUrl() {
9+
return "https://www.change.photos/api";
10+
},
11+
_makeRequest({
12+
$ = this,
13+
path,
14+
...otherOpts
15+
}) {
16+
return axios($, {
17+
...otherOpts,
18+
url: `${this._baseUrl()}${path}`,
19+
headers: {
20+
Authorization: `Bearer ${this.$auth.api_key}`,
21+
},
22+
});
23+
},
24+
transformImage(opts = {}) {
25+
return this._makeRequest({
26+
method: "POST",
27+
path: "/change",
28+
...opts,
29+
});
930
},
1031
},
1132
};

components/change_photos/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/change_photos",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream change.photos Components",
55
"main": "change_photos.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)