n8n-nodes-pictomancer 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pictomancer.ai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # n8n-nodes-pictomancer
2
+
3
+ [n8n](https://n8n.io) community node for [Pictomancer.ai](https://pictomancer.ai) - image optimization in your workflows: resize, compress, convert (JPEG/PNG/WebP/TIFF/GIF/AVIF), crop, and multi-step pipelines.
4
+
5
+ ## Install
6
+
7
+ In n8n: **Settings → Community Nodes → Install** and enter `n8n-nodes-pictomancer`.
8
+
9
+ Or with npm (self-hosted):
10
+
11
+ ```bash
12
+ npm install n8n-nodes-pictomancer
13
+ ```
14
+
15
+ ## Credentials
16
+
17
+ Create a **Pictomancer API** credential:
18
+
19
+ - **API Key** - Bearer token from [app.pictomancer.ai](https://app.pictomancer.ai). Optional: without it you are on the free tier (50 requests per IP).
20
+ - **Base URL** - defaults to `https://api.pictomancer.ai`.
21
+
22
+ ## Operations
23
+
24
+ | Operation | Input | Output |
25
+ |-----------|-------|--------|
26
+ | Analyze | URL or binary | JSON metadata (`size_bytes`) |
27
+ | Resize | URL or binary | Binary image |
28
+ | Compress | URL or binary | Binary image |
29
+ | Convert | URL or binary | Binary image |
30
+ | Crop | URL or binary | Binary image |
31
+ | Pipeline | URL or binary | Binary image |
32
+
33
+ - **Input Type** switches between a source URL and binary data from the previous node (sent as a `data:` URI).
34
+ - Image operations output binary data (default property `data`) plus `size_bytes`, `mime_type`, and `billed` in the item JSON. `billed` is `false` when compress produced no size gain - those requests are free.
35
+ - **Options** exposes quality (`q`), output format, metadata strip, lossless, and the AVIF `effort` knob.
36
+ - **Pipeline** takes a JSON list of steps, e.g. `[{ "type": "resize", "params": { "scale": "0.5" } }, { "type": "convert", "params": { "format": "webp" } }]`.
37
+
38
+ ## Development
39
+
40
+ ```bash
41
+ npm install
42
+ npm test
43
+ npm run build
44
+ ```
45
+
46
+ ## License
47
+
48
+ MIT
@@ -0,0 +1,9 @@
1
+ import type { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from "n8n-workflow";
2
+ export declare class PictomancerApi implements ICredentialType {
3
+ name: string;
4
+ displayName: string;
5
+ documentationUrl: string;
6
+ properties: INodeProperties[];
7
+ authenticate: IAuthenticateGeneric;
8
+ test: ICredentialTestRequest;
9
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PictomancerApi = void 0;
4
+ class PictomancerApi {
5
+ name = "pictomancerApi";
6
+ displayName = "Pictomancer API";
7
+ documentationUrl = "https://pictomancer.ai";
8
+ properties = [
9
+ {
10
+ displayName: "API Key",
11
+ name: "apiKey",
12
+ type: "string",
13
+ typeOptions: { password: true },
14
+ default: "",
15
+ description: "Bearer token from app.pictomancer.ai. Leave empty to use the free tier (50 requests per IP).",
16
+ },
17
+ {
18
+ displayName: "Base URL",
19
+ name: "baseUrl",
20
+ type: "string",
21
+ default: "https://api.pictomancer.ai",
22
+ },
23
+ ];
24
+ authenticate = {
25
+ type: "generic",
26
+ properties: {
27
+ headers: {
28
+ Authorization: '={{$credentials.apiKey ? "Bearer " + $credentials.apiKey : undefined}}',
29
+ },
30
+ },
31
+ };
32
+ test = {
33
+ request: {
34
+ baseURL: "={{$credentials.baseUrl}}",
35
+ url: "/v1/info",
36
+ },
37
+ };
38
+ }
39
+ exports.PictomancerApi = PictomancerApi;
@@ -0,0 +1,5 @@
1
+ import type { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
2
+ export declare class Pictomancer implements INodeType {
3
+ description: INodeTypeDescription;
4
+ execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]>;
5
+ }
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Pictomancer = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const operations_1 = require("./operations");
6
+ class Pictomancer {
7
+ description = {
8
+ displayName: "Pictomancer",
9
+ name: "pictomancer",
10
+ icon: "file:pictomancer.svg",
11
+ group: ["transform"],
12
+ version: 1,
13
+ subtitle: '={{$parameter["operation"]}}',
14
+ description: "Optimize images with Pictomancer.ai",
15
+ defaults: { name: "Pictomancer" },
16
+ inputs: ["main"],
17
+ outputs: ["main"],
18
+ credentials: [{ name: "pictomancerApi", required: true }],
19
+ properties: [
20
+ {
21
+ displayName: "Operation",
22
+ name: "operation",
23
+ type: "options",
24
+ noDataExpression: true,
25
+ default: "compress",
26
+ options: [
27
+ { name: "Analyze", value: "analyze", action: "Analyze an image" },
28
+ { name: "Compress", value: "compress", action: "Compress an image" },
29
+ { name: "Convert", value: "convert", action: "Convert image format" },
30
+ { name: "Crop", value: "crop", action: "Crop an image" },
31
+ { name: "Pipeline", value: "pipeline", action: "Run an operation pipeline" },
32
+ { name: "Resize", value: "resize", action: "Resize an image" },
33
+ ],
34
+ },
35
+ {
36
+ displayName: "Input Type",
37
+ name: "inputType",
38
+ type: "options",
39
+ noDataExpression: true,
40
+ default: "url",
41
+ options: [
42
+ { name: "URL", value: "url" },
43
+ { name: "Binary Data", value: "binary" },
44
+ ],
45
+ },
46
+ {
47
+ displayName: "Source URL",
48
+ name: "source",
49
+ type: "string",
50
+ default: "",
51
+ required: true,
52
+ placeholder: "https://example.com/image.jpg",
53
+ displayOptions: { show: { inputType: ["url"] } },
54
+ },
55
+ {
56
+ displayName: "Input Binary Field",
57
+ name: "binaryPropertyName",
58
+ type: "string",
59
+ default: "data",
60
+ required: true,
61
+ displayOptions: { show: { inputType: ["binary"] } },
62
+ },
63
+ {
64
+ displayName: "Scale",
65
+ name: "scale",
66
+ type: "number",
67
+ default: 0.5,
68
+ description: "Uniform scale factor (e.g. 0.5 = half size)",
69
+ displayOptions: { show: { operation: ["resize"] } },
70
+ },
71
+ {
72
+ displayName: "Format",
73
+ name: "format",
74
+ type: "options",
75
+ default: "webp",
76
+ options: [
77
+ { name: "AVIF", value: "avif" },
78
+ { name: "GIF", value: "gif" },
79
+ { name: "JPEG", value: "jpeg" },
80
+ { name: "PNG", value: "png" },
81
+ { name: "TIFF", value: "tiff" },
82
+ { name: "WebP", value: "webp" },
83
+ ],
84
+ displayOptions: { show: { operation: ["convert"] } },
85
+ },
86
+ {
87
+ displayName: "X",
88
+ name: "x",
89
+ type: "number",
90
+ default: 0,
91
+ displayOptions: { show: { operation: ["crop"] } },
92
+ },
93
+ {
94
+ displayName: "Y",
95
+ name: "y",
96
+ type: "number",
97
+ default: 0,
98
+ displayOptions: { show: { operation: ["crop"] } },
99
+ },
100
+ {
101
+ displayName: "Width",
102
+ name: "width",
103
+ type: "number",
104
+ default: 100,
105
+ displayOptions: { show: { operation: ["crop"] } },
106
+ },
107
+ {
108
+ displayName: "Height",
109
+ name: "height",
110
+ type: "number",
111
+ default: 100,
112
+ displayOptions: { show: { operation: ["crop"] } },
113
+ },
114
+ {
115
+ displayName: "Operations (JSON)",
116
+ name: "pipelineOperations",
117
+ type: "json",
118
+ default: '[\n { "type": "resize", "params": { "scale": "0.5" } },\n { "type": "convert", "params": { "format": "webp" } }\n]',
119
+ description: "Ordered list of pipeline steps, each {type, params}",
120
+ displayOptions: { show: { operation: ["pipeline"] } },
121
+ },
122
+ {
123
+ displayName: "Options",
124
+ name: "options",
125
+ type: "collection",
126
+ placeholder: "Add option",
127
+ default: {},
128
+ displayOptions: { show: { operation: ["resize", "compress", "convert"] } },
129
+ options: [
130
+ {
131
+ displayName: "Effort (AVIF)",
132
+ name: "effort",
133
+ type: "number",
134
+ typeOptions: { minValue: 0, maxValue: 9 },
135
+ default: 2,
136
+ description: "AV1 encoder CPU effort (0-9). Higher = smaller files, slower.",
137
+ },
138
+ {
139
+ displayName: "Lossless",
140
+ name: "lossless",
141
+ type: "boolean",
142
+ default: false,
143
+ description: "Whether to encode losslessly (WebP and AVIF)",
144
+ },
145
+ {
146
+ displayName: "Output Format",
147
+ name: "format",
148
+ type: "string",
149
+ default: "",
150
+ description: "Output format for resize/compress (jpeg, png, webp, tiff, gif, avif)",
151
+ },
152
+ {
153
+ displayName: "Quality",
154
+ name: "q",
155
+ type: "number",
156
+ typeOptions: { minValue: 1, maxValue: 100 },
157
+ default: 85,
158
+ },
159
+ {
160
+ displayName: "Scale X",
161
+ name: "scale_x",
162
+ type: "number",
163
+ default: 0,
164
+ description: "Horizontal scale factor (overrides Scale together with Scale Y)",
165
+ },
166
+ {
167
+ displayName: "Scale Y",
168
+ name: "scale_y",
169
+ type: "number",
170
+ default: 0,
171
+ description: "Vertical scale factor (overrides Scale together with Scale X)",
172
+ },
173
+ {
174
+ displayName: "Strip Metadata",
175
+ name: "strip",
176
+ type: "boolean",
177
+ default: false,
178
+ },
179
+ ],
180
+ },
181
+ {
182
+ displayName: "Output Binary Field",
183
+ name: "outputBinaryPropertyName",
184
+ type: "string",
185
+ default: "data",
186
+ displayOptions: { show: { operation: ["resize", "compress", "convert", "crop", "pipeline"] } },
187
+ },
188
+ ],
189
+ };
190
+ async execute() {
191
+ const items = this.getInputData();
192
+ const returnData = [];
193
+ const credentials = await this.getCredentials("pictomancerApi");
194
+ const baseUrl = String(credentials.baseUrl ?? "https://api.pictomancer.ai").replace(/\/$/, "");
195
+ for (let i = 0; i < items.length; i++) {
196
+ try {
197
+ const operation = this.getNodeParameter("operation", i);
198
+ const source = await resolveSource(this, i);
199
+ const params = collectParams(this, operation, i);
200
+ const { path, body } = (0, operations_1.buildOperationRequest)(operation, source, params);
201
+ const response = await this.helpers.httpRequestWithAuthentication.call(this, "pictomancerApi", {
202
+ method: "POST",
203
+ url: `${baseUrl}${path}`,
204
+ body,
205
+ json: true,
206
+ encoding: "arraybuffer",
207
+ returnFullResponse: true,
208
+ });
209
+ const contentType = String(response.headers["content-type"] ?? "");
210
+ if (operation === "analyze" || contentType.startsWith("application/json")) {
211
+ const text = Buffer.from(response.body).toString("utf-8");
212
+ returnData.push({ json: JSON.parse(text), pairedItem: { item: i } });
213
+ continue;
214
+ }
215
+ const outputProperty = this.getNodeParameter("outputBinaryPropertyName", i);
216
+ const buffer = Buffer.from(response.body);
217
+ const binary = await this.helpers.prepareBinaryData(buffer, undefined, contentType);
218
+ returnData.push({
219
+ json: {
220
+ size_bytes: buffer.length,
221
+ mime_type: contentType,
222
+ billed: response.headers["x-pig-billed"] === "1",
223
+ },
224
+ binary: { [outputProperty]: binary },
225
+ pairedItem: { item: i },
226
+ });
227
+ }
228
+ catch (error) {
229
+ if (this.continueOnFail()) {
230
+ returnData.push({
231
+ json: { error: error.message },
232
+ pairedItem: { item: i },
233
+ });
234
+ continue;
235
+ }
236
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
237
+ }
238
+ }
239
+ return [returnData];
240
+ }
241
+ }
242
+ exports.Pictomancer = Pictomancer;
243
+ async function resolveSource(ctx, itemIndex) {
244
+ const inputType = ctx.getNodeParameter("inputType", itemIndex);
245
+ if (inputType === "url") {
246
+ return ctx.getNodeParameter("source", itemIndex);
247
+ }
248
+ const propertyName = ctx.getNodeParameter("binaryPropertyName", itemIndex);
249
+ const binaryData = ctx.helpers.assertBinaryData(itemIndex, propertyName);
250
+ const buffer = await ctx.helpers.getBinaryDataBuffer(itemIndex, propertyName);
251
+ return (0, operations_1.toDataUri)(binaryData.mimeType ?? "application/octet-stream", buffer.toString("base64"));
252
+ }
253
+ function collectParams(ctx, operation, itemIndex) {
254
+ if (operation === "analyze")
255
+ return {};
256
+ if (operation === "crop") {
257
+ return {
258
+ x: ctx.getNodeParameter("x", itemIndex),
259
+ y: ctx.getNodeParameter("y", itemIndex),
260
+ width: ctx.getNodeParameter("width", itemIndex),
261
+ height: ctx.getNodeParameter("height", itemIndex),
262
+ };
263
+ }
264
+ if (operation === "pipeline") {
265
+ const raw = ctx.getNodeParameter("pipelineOperations", itemIndex);
266
+ const operations = typeof raw === "string" ? JSON.parse(raw) : raw;
267
+ return { operations };
268
+ }
269
+ const params = {
270
+ ...ctx.getNodeParameter("options", itemIndex, {}),
271
+ };
272
+ if (operation === "resize") {
273
+ // scale_x/scale_y in Options take precedence over the plain Scale knob
274
+ if (!params.scale_x && !params.scale_y) {
275
+ params.scale = ctx.getNodeParameter("scale", itemIndex);
276
+ }
277
+ else {
278
+ delete params.scale;
279
+ }
280
+ if (!params.scale_x)
281
+ delete params.scale_x;
282
+ if (!params.scale_y)
283
+ delete params.scale_y;
284
+ }
285
+ if (operation === "convert") {
286
+ params.format = ctx.getNodeParameter("format", itemIndex);
287
+ }
288
+ return params;
289
+ }
@@ -0,0 +1,13 @@
1
+ export interface OperationRequest {
2
+ path: string;
3
+ body: Record<string, unknown>;
4
+ }
5
+ export type OperationParams = Record<string, unknown>;
6
+ /**
7
+ * Map an n8n operation + collected parameters to the API request.
8
+ * Empty strings and undefined are dropped so optional node fields
9
+ * never reach the API as explicit values.
10
+ */
11
+ export declare function buildOperationRequest(operation: string, source: string, params: OperationParams): OperationRequest;
12
+ /** data: URI for binary inputs so any upstream item can be a source. */
13
+ export declare function toDataUri(mimeType: string, base64: string): string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildOperationRequest = buildOperationRequest;
4
+ exports.toDataUri = toDataUri;
5
+ const OPERATION_PATHS = {
6
+ analyze: "/v1/analyze",
7
+ resize: "/v1/resize",
8
+ compress: "/v1/compress",
9
+ convert: "/v1/convert",
10
+ crop: "/v1/crop",
11
+ pipeline: "/v1/pipeline",
12
+ };
13
+ /**
14
+ * Map an n8n operation + collected parameters to the API request.
15
+ * Empty strings and undefined are dropped so optional node fields
16
+ * never reach the API as explicit values.
17
+ */
18
+ function buildOperationRequest(operation, source, params) {
19
+ const path = OPERATION_PATHS[operation];
20
+ if (path === undefined) {
21
+ throw new Error(`unsupported operation: ${operation}`);
22
+ }
23
+ const body = { source };
24
+ for (const [key, value] of Object.entries(params)) {
25
+ if (value === undefined || value === "")
26
+ continue;
27
+ body[key] = value;
28
+ }
29
+ return { path, body };
30
+ }
31
+ /** data: URI for binary inputs so any upstream item can be a source. */
32
+ function toDataUri(mimeType, base64) {
33
+ return `data:${mimeType};base64,${base64}`;
34
+ }
@@ -0,0 +1,9 @@
1
+ <svg viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <defs>
3
+ <clipPath id="c">
4
+ <circle cx="256" cy="256" r="220"/>
5
+ </clipPath>
6
+ </defs>
7
+ <circle cx="256" cy="256" r="220" fill="#a855f7"/>
8
+ <circle cx="172" cy="155" r="190" fill="white" opacity="0.35" clip-path="url(#c)"/>
9
+ </svg>
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "n8n-nodes-pictomancer",
3
+ "version": "0.1.0",
4
+ "description": "n8n community node for Pictomancer.ai - image optimization (resize, compress, convert, crop, pipeline)",
5
+ "license": "MIT",
6
+ "homepage": "https://pictomancer.ai",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/pictomancer/n8n-nodes-pictomancer.git"
10
+ },
11
+ "main": "index.js",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "keywords": [
16
+ "n8n-community-node-package",
17
+ "image",
18
+ "optimization",
19
+ "resize",
20
+ "compress",
21
+ "avif",
22
+ "webp",
23
+ "pictomancer"
24
+ ],
25
+ "engines": {
26
+ "node": ">=20.15"
27
+ },
28
+ "n8n": {
29
+ "n8nNodesApiVersion": 1,
30
+ "credentials": [
31
+ "dist/credentials/PictomancerApi.credentials.js"
32
+ ],
33
+ "nodes": [
34
+ "dist/nodes/Pictomancer/Pictomancer.node.js"
35
+ ]
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json && node -e \"require('node:fs').copyFileSync('nodes/Pictomancer/pictomancer.svg','dist/nodes/Pictomancer/pictomancer.svg')\"",
39
+ "test": "vitest run",
40
+ "typecheck": "tsc --noEmit"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^18.19.130",
44
+ "n8n-workflow": "^1.70.0",
45
+ "typescript": "^5.4.0",
46
+ "vitest": "^3.0.0"
47
+ },
48
+ "peerDependencies": {
49
+ "n8n-workflow": "*"
50
+ }
51
+ }