Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions components/change_photos/actions/transform-image/transform-image.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import changePhotos from "../../change_photos.app.mjs";
import { ConfigurationError } from "@pipedream/platform";

export default {
key: "change_photos-transform-image",
name: "Transform Image",
description: "Transforms an image with various effects and optimizations. [See the documentation](https://www.change.photos/api-docs)",
version: "0.0.1",
type: "action",
props: {
changePhotos,
imageUrl: {
type: "string",
label: "Image URL",
description: "URL of the image to transform",
},
width: {
type: "integer",
label: "Width",
description: "Desired width in pixels of the output image",
optional: true,
},
height: {
type: "integer",
label: "Height",
description: "Desired height in pixels of the output image",
optional: true,
},
format: {
type: "string",
label: "Format",
description: "Output image format. Default: `jpeg`",
options: [
"jpeg",
"png",
"webp",
],
optional: true,
},
quality: {
type: "integer",
label: "Quality",
description: "Output image quality. Must be between `1` and `100`. Default: `80`",
optional: true,
},
fit: {
type: "string",
label: "Fit",
description: "How the image should fit within the dimensions. Default: `contain`",
options: [
"contain",
"cover",
"fill",
"inside",
"outside",
],
optional: true,
},
flip: {
type: "boolean",
label: "Flip",
description: "Flip the image vertically",
optional: true,
},
flop: {
type: "boolean",
label: "Flop",
description: "Flip the image horizontally",
optional: true,
},
rotate: {
type: "integer",
label: "Rotate",
description: "Rotation angle in degrees. Must be between `-360` and `360`. Default: `0`",
optional: true,
},
grayscale: {
type: "boolean",
label: "Grayscale",
description: "Convert image to grayscale",
optional: true,
},
blur: {
type: "string",
label: "Blur",
description: "Gaussian blur sigma value. Must be between `0.3` and `1000`.",
optional: true,
},
sharpen: {
type: "boolean",
label: "Sharpen",
description: "Apply sharpening effect",
optional: true,
},
compress: {
type: "boolean",
label: "Compress",
description: "Apply additional compression",
optional: true,
},
tintRedComponent: {
type: "string",
label: "Tint - Red Component",
description: "Red Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
optional: true,
},
tintGreenComponent: {
type: "string",
label: "Tint - Green Component",
description: "Green Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
optional: true,
},
tintBlueComponent: {
type: "string",
label: "Tint - Blue Component",
description: "Blue Component of the RGB tint to apply to the image. Must be between `0` and `255`.",
optional: true,
},
},
async run({ $ }) {
if (
(this.tintRedComponent || this.tintGreenComponent || this.tintBlueComponent)
&& !(this.tintRedComponent && this.tintGreenComponent && this.tintBlueComponent)
) {
throw new ConfigurationError("Must specify Red, Green, and Blue RGB components to apply tint");
}

const response = await this.changePhotos.transformImage({
$,
data: {
url: this.imageUrl,
width: this.width,
height: this.height,
format: this.format,
quality: this.quality,
fit: this.fit,
flip: this.flip,
flop: this.flop,
rotate: this.rotate,
grayscale: this.grayscale,
blur: this.blur && +this.blur,
sharpen: this.sharpen,
compress: this.compress,
tint: this.tintRedComponent && {
r: +this.tintRedComponent,
g: +this.tintGreenComponent,
b: +this.tintBlueComponent,
},
},
});

$.export("$summary", "Image transformed successfully");
return response;
},
};
28 changes: 25 additions & 3 deletions components/change_photos/change_photos.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "change_photos",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://www.change.photos/api";
},
_makeRequest({
$ = this,
path,
...otherOpts
}) {
return axios($, {
...otherOpts,
url: `${this._baseUrl()}${path}`,
headers: {
Authorization: `Bearer ${this.$auth.api_key}`,
},
debug: true,
});
},
transformImage(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/change",
...opts,
});
},
},
};
7 changes: 5 additions & 2 deletions components/change_photos/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/change_photos",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream change.photos Components",
"main": "change_photos.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
9 changes: 6 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading