Skip to content

Commit abe2c20

Browse files
committed
Reworking image transformation
1 parent d9a54c5 commit abe2c20

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

components/cloudinary/actions/image-transformation/image-transformation.mjs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,64 @@ import cloudinary from "../../cloudinary.app.mjs";
22

33
export default {
44
key: "cloudinary-image-transformation",
5-
name: "Image Transformation",
6-
description: "Transforms images on-the-fly. It modifies them to any required format, style and dimension, resize and crop the images, etc. [See the documentation](https://cloudinary.com/documentation/image_transformations)",
7-
version: "0.1.2",
5+
name: "Transform Image",
6+
description: "Transform an image on-the-fly with several options. [See the documentation](https://cloudinary.com/documentation/image_transformations)",
7+
version: "0.1.{{ts}}",
88
type: "action",
99
props: {
1010
cloudinary,
1111
imageSource: {
1212
type: "string",
1313
label: "Public ID",
14-
description: "The [public ID](https://cloudinary.com/documentation/upload_images#public_id) that references a file you've previously uploaded to Cloudinary, e.g. `folder/filename`.",
14+
description: "The [public ID](https://cloudinary.com/documentation/upload_images#public_id) of the asset , e.g. `folder/filename`.",
1515
},
16-
options: {
16+
width: {
17+
type: "integer",
18+
label: "Width",
19+
description: "The new width of the image, e.g. `300`",
20+
optional: true,
21+
},
22+
height: {
23+
type: "integer",
24+
label: "Height",
25+
description: "The new height of the image, e.g. `300`",
26+
optional: true,
27+
},
28+
background: {
29+
type: "string",
30+
label: "Background",
31+
description: "The background color to apply on transparent areas of the image, as a named color or RGB(A) value, e.g. `blue` or `8B0`",
32+
optional: true,
33+
},
34+
opacity: {
35+
type: "integer",
36+
label: "Opacity",
37+
description: "The opacity level to set for the image, from 0 to 100",
38+
optional: true,
39+
min: 0,
40+
max: 100,
41+
},
42+
transformations: {
1743
type: "object",
18-
label: "Options",
19-
description: "The image transformation options to apply and/or the URL parameters supported by Cloudinary API. For all transformation options, please check [Image transformation API reference](https://cloudinary.com/documentation/image_transformation_reference), for URL parameters, please check [Transforming media assets using dynamic URLs](https://cloudinary.com/documentation/image_transformations#transforming_media_assets_using_dynamic_urls)",
44+
label: "Additional Transformations",
45+
description: "Additional transformations to apply to the image. [See the documentation](https://cloudinary.com/documentation/transformation_reference#co_color) for all available transformations. Example: `{ \"angle\": 90, \"color_space\": \"srgb\"}`",
2046
},
2147
},
2248
async run({ $ }) {
23-
const response = await this.cloudinary.transformImage(this.imageSource, this.options);
49+
const { cloudinary, imageSource, transformations, ...options } = this;
50+
try {
51+
const response = await cloudinary.transformImage(imageSource, {
52+
...options,
53+
...transformations,
54+
});
2455

2556
if (response) {
2657
$.export("$summary", "Successfully transformed image.");
2758
}
2859

2960
return response;
61+
} catch (err) {
62+
throw new Error(`Cloudinary error response: ${err.error?.message ?? JSON.stringify(err)}`);
63+
}
3064
},
3165
};

components/cloudinary/cloudinary.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default {
7070
return this._client().api.usage(options);
7171
},
7272
async transformImage(imageSource, options) {
73-
return this._client().image(imageSource, options);
73+
return this._client().url(imageSource, options);
7474
},
7575
async transformVideo(videoPublicId, options) {
7676
return this._client().video(videoPublicId, options);

0 commit comments

Comments
 (0)