|
| 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 | +}; |
0 commit comments