feat: Remove Edit Image v1-1.1

This commit is contained in:
Yehor Kardash authored and n8n-assistant[bot] committed 2026-11-30 06:22:31 +00:00
1 parent 979e72d472
commit 4527a72db6
10 files changed
+29 -2551

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ ARG PNPM_VERSION=12.4.2
RUN apk add --no-cache \
openssh sudo shadow bash libc-utils \
git openssl graphicsmagick tini tzdata ca-certificates libc6-compat
git openssl tini tzdata ca-certificates libc6-compat
RUN echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/node && chmod 0440 /etc/sudoers.d/node
RUN mkdir /workspaces && chown node:node /workspaces
RUN npm i -g "pnpm@${PNPM_VERSION}"
-1
View File
@@ -19,7 +19,6 @@ RUN apk add --no-cache busybox-binsh && \
# libs Node uses (the openssl CLI binary isn't needed at runtime).
apk add --no-cache \
openssh \
graphicsmagick \
tini \
tzdata \
ca-certificates \
@@ -1154,7 +1154,7 @@ const BASE64_BODY_RE = /^[A-Za-z0-9+/=\s]+$/;
* CONTENT but cannot author valid binary: a PDF part's body (plaintext per the
* quirk guidance, or a garbage base64 stub) becomes a real PDF carrying that
* text; image parts get the standard decodable fixture. Downstream parsers
* (Extract PDF Text via pdfjs, Edit Image via GraphicsMagick) then run on
* (Extract PDF Text via pdfjs and Edit Image) then run on
* structurally valid bytes instead of crashing.
*/
export function substituteBinaryMimeParts(rfc822: string): string {
@@ -37,7 +37,7 @@ export interface ProviderRequestInfo {
}
// Generated image bytes must be REAL: workflows routinely pipe them into
// image-processing nodes (Edit Image → GraphicsMagick), which crash on a
// image-processing nodes such as Edit Image, which crash on a
// truncated or 1×1 placeholder ("Insufficient image data"). The model cannot
// author valid image bytes, so every b64_json is substituted with a decodable
// drawable canvas.
@@ -241,11 +241,10 @@ let canvasPngCache: Buffer | undefined;
/**
* 512×512 opaque white PNG (8-bit grayscale), built programmatically so it is
* always structurally valid. It is the `image/png` download fixture and gives
* image-PROCESSING nodes (Edit Image text overlay, resize, composite via
* GraphicsMagick) a real canvas to operate on — a 1×1 or truncated placeholder
* makes them fail with "Insufficient image data", and a PNG with a bad chunk
* CRC makes GraphicsMagick write nothing ("Stream yields empty buffer").
* always structurally valid. Unlike `PNG_1X1`, this gives image-PROCESSING
* nodes (Edit Image text overlay, resize, and composite operations) a real
* canvas to operate on — a 1×1 or truncated placeholder makes them fail with
* "Insufficient image data".
*/
export function evalCanvasPng(): Buffer {
if (canvasPngCache) return canvasPngCache;
@@ -1,83 +1,17 @@
import { writeFile as fsWriteFile } from 'fs/promises';
import getSystemFonts from 'get-system-fonts';
import gm from 'gm';
import type {
IBinaryData,
IDataObject,
IExecuteFunctions,
ILoadOptionsFunctions,
INode,
INodeExecutionData,
INodeProperties,
INodePropertyOptions,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import { NodeOperationError, NodeConnectionTypes, deepCopy } from 'n8n-workflow';
import { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';
import { parse as pathParse } from 'path';
import { file } from 'tmp-promise';
import { router } from './v2/actions/router';
type EditImageNodeOptions = {
destinationKey?: string;
font?: string;
fileName?: string;
format?: string;
quality?: number;
};
const GRAVITY_MAP: { [horizontal: string]: { [vertical: string]: string } } = {
west: { north: 'northwest', middle: 'west', south: 'southwest' },
center: { north: 'north', middle: 'center', south: 'south' },
east: { north: 'northeast', middle: 'east', south: 'southeast' },
};
export function resolveGravity(horizontal: string, vertical: string): string {
return GRAVITY_MAP[horizontal]?.[vertical] ?? 'northwest';
}
const numericOperationParameters: Record<string, string[]> = {
blur: ['blur', 'sigma'],
border: ['borderWidth', 'borderHeight'],
composite: ['positionX', 'positionY'],
create: ['width', 'height'],
crop: ['width', 'height', 'positionX', 'positionY'],
draw: ['startPositionX', 'startPositionY', 'endPositionX', 'endPositionY', 'cornerRadius'],
resize: ['width', 'height'],
rotate: ['rotate'],
shear: ['degreesX', 'degreesY'],
text: ['fontSize', 'positionX', 'positionY', 'lineLength'],
};
function parseNumericParameter(value: unknown, parameterName: string, node: INode): number {
if (
(typeof value !== 'number' && typeof value !== 'string') ||
(typeof value === 'string' && value.trim() === '')
) {
throw new NodeOperationError(node, `The value of "${parameterName}" must be a number`);
}
const parsedValue = Number(value);
if (!Number.isFinite(parsedValue)) {
throw new NodeOperationError(node, `The value of "${parameterName}" must be a number`);
}
return parsedValue;
}
const VALID_IMAGE_FORMATS = new Set(['bmp', 'gif', 'jpeg', 'png', 'tiff', 'tif', 'webp']);
function validateImageFormat(format: unknown, node: INode): string {
if (typeof format === 'string' && VALID_IMAGE_FORMATS.has(format)) {
return format;
}
throw new NodeOperationError(
node,
`Invalid image format: ${format}. Valid formats are: ${Array.from(VALID_IMAGE_FORMATS).join(', ')}`,
);
}
const nodeOperations: INodePropertyOptions[] = [
{
name: 'Blur',
@@ -906,7 +840,7 @@ export class EditImage implements INodeType {
properties: [
{
displayName:
'This node version is deprecated. Upgrade to version 2. Image output can look different because version 2 uses a different processing library.',
'This node version is no longer supported. Upgrade to version 2 to run this workflow.',
name: 'legacyVersionNotice',
type: 'notice',
default: '',
@@ -1155,409 +1089,14 @@ export class EditImage implements INodeType {
},
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
if (this.getNode().typeVersion >= 2) {
return await router.call(this);
async execute(this: IExecuteFunctions) {
if (this.getNode().typeVersion < 2) {
throw new NodeOperationError(
this.getNode(),
'Edit Image versions 1 and 1.1 are no longer supported. Upgrade the node to version 2.',
);
}
const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
const length = items.length;
let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < length; itemIndex++) {
try {
item = items[itemIndex];
const node = this.getNode();
const operation = this.getNodeParameter('operation', itemIndex);
const dataPropertyName = this.getNodeParameter('dataPropertyName', itemIndex) as
| string
| IBinaryData;
const options = this.getNodeParameter('options', itemIndex, {}) as EditImageNodeOptions;
let binaryPropertyName = options.destinationKey;
if (!binaryPropertyName) {
binaryPropertyName = typeof dataPropertyName === 'string' ? dataPropertyName : 'data';
}
const cleanupFunctions: Array<() => void> = [];
let gmInstance: gm.State;
const requiredOperationParameters: {
[key: string]: string[];
} = {
blur: ['blur', 'sigma'],
border: ['borderColor', 'borderWidth', 'borderHeight'],
create: ['backgroundColor', 'height', 'width'],
crop: ['height', 'positionX', 'positionY', 'width'],
composite: ['dataPropertyNameComposite', 'operator', 'positionX', 'positionY'],
draw: [
'color',
'cornerRadius',
'endPositionX',
'endPositionY',
'primitive',
'startPositionX',
'startPositionY',
],
information: [],
resize: ['height', 'resizeOption', 'width'],
rotate: ['backgroundColor', 'rotate'],
shear: ['degreesX', 'degreesY'],
text: [
'horizontalAlignment',
'verticalAlignment',
'font',
'fontColor',
'fontSize',
'lineLength',
'positionX',
'positionY',
'text',
],
transparent: ['color'],
};
let operations: IDataObject[] = [];
if (operation === 'multiStep') {
// Operation parameters are already in the correct format
const operationsData = this.getNodeParameter('operations', itemIndex, {
operations: [],
}) as IDataObject;
operations = operationsData.operations as IDataObject[];
} else {
// Operation parameters have to first get collected
const operationParameters: IDataObject = {};
requiredOperationParameters[operation].forEach((parameterName) => {
try {
operationParameters[parameterName] = this.getNodeParameter(parameterName, itemIndex);
} catch (error) {}
});
operations = [
{
operation,
...operationParameters,
},
];
}
for (const operationData of operations) {
const operationName = operationData.operation;
if (typeof operationName !== 'string') continue;
for (const parameterName of numericOperationParameters[operationName] ?? []) {
// 'cornerRadius' is applicable only when drawing a rectangle
if (parameterName === 'cornerRadius' && operationData.primitive !== 'rectangle')
continue;
operationData[parameterName] = parseNumericParameter(
operationData[parameterName],
parameterName,
node,
);
}
}
if (options.quality !== undefined) {
options.quality = parseNumericParameter(options.quality, 'quality', node);
}
if (operations[0].operation !== 'create') {
// "create" generates a new image so does not require any incoming data.
this.helpers.assertBinaryData(itemIndex, dataPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex,
dataPropertyName,
);
gmInstance = gm(binaryDataBuffer);
gmInstance = gmInstance.background('transparent');
gmInstance = gmInstance.autoOrient();
gmInstance = gmInstance.out('-orient', 'TopLeft');
}
const newItem: INodeExecutionData = {
json: item.json,
binary: {},
pairedItem: {
item: itemIndex,
},
};
if (operation === 'information') {
// Just return the information
const imageData = await new Promise<IDataObject>((resolve, reject) => {
gmInstance = gmInstance.identify((error, data) => {
if (error) {
reject(error);
return;
}
resolve(data as unknown as IDataObject);
});
});
newItem.json = imageData;
}
for (let i = 0; i < operations.length; i++) {
const operationData = operations[i];
if (operationData.operation === 'blur') {
gmInstance = gmInstance!.blur(
operationData.blur as number,
operationData.sigma as number,
);
} else if (operationData.operation === 'border') {
gmInstance = gmInstance!
.borderColor(operationData.borderColor as string)
.border(operationData.borderWidth as number, operationData.borderHeight as number);
} else if (operationData.operation === 'composite') {
const positionX = operationData.positionX as number;
const positionY = operationData.positionY as number;
const operator = operationData.operator as string;
const geometryString =
(positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
const binaryPropertyName = operationData.dataPropertyNameComposite as string;
this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(
itemIndex,
binaryPropertyName,
);
const { path, cleanup } = await file();
cleanupFunctions.push(cleanup);
await fsWriteFile(path, binaryDataBuffer);
gmInstance = gm(gmInstance!.stream('png'))
.compose(operator)
.geometry(geometryString)
.composite(path);
if (operations.length !== i + 1) {
// If there are other operations after the current one create a new gm instance
// because else things do get messed up
gmInstance = gm(gmInstance.stream());
}
} else if (operationData.operation === 'create') {
gmInstance = gm(
operationData.width as number,
operationData.height as number,
operationData.backgroundColor as string,
);
if (!options.format) {
options.format = 'png';
}
} else if (operationData.operation === 'crop') {
gmInstance = gmInstance!.crop(
operationData.width as number,
operationData.height as number,
operationData.positionX as number,
operationData.positionY as number,
);
} else if (operationData.operation === 'draw') {
gmInstance = gmInstance!.fill(operationData.color as string);
if (operationData.primitive === 'line') {
gmInstance = gmInstance.drawLine(
operationData.startPositionX as number,
operationData.startPositionY as number,
operationData.endPositionX as number,
operationData.endPositionY as number,
);
} else if (operationData.primitive === 'circle') {
gmInstance = gmInstance.drawCircle(
operationData.startPositionX as number,
operationData.startPositionY as number,
operationData.endPositionX as number,
operationData.endPositionY as number,
);
} else if (operationData.primitive === 'rectangle') {
gmInstance = gmInstance.drawRectangle(
operationData.startPositionX as number,
operationData.startPositionY as number,
operationData.endPositionX as number,
operationData.endPositionY as number,
(operationData.cornerRadius as number) || undefined,
);
}
} else if (operationData.operation === 'resize') {
const resizeOption = operationData.resizeOption as string;
// By default use "maximumArea"
let option: gm.ResizeOption = '@';
if (resizeOption === 'ignoreAspectRatio') {
option = '!';
} else if (resizeOption === 'minimumArea') {
option = '^';
} else if (resizeOption === 'onlyIfSmaller') {
option = '<';
} else if (resizeOption === 'onlyIfLarger') {
option = '>';
} else if (resizeOption === 'percent') {
option = '%';
}
gmInstance = gmInstance!.resize(
operationData.width as number,
operationData.height as number,
option,
);
} else if (operationData.operation === 'rotate') {
gmInstance = gmInstance!.rotate(
operationData.backgroundColor as string,
operationData.rotate as number,
);
} else if (operationData.operation === 'shear') {
gmInstance = gmInstance!.shear(
operationData.degreesX as number,
operationData.degreesY as number,
);
} else if (operationData.operation === 'text') {
// Split the text in multiple lines
const lines: string[] = [];
let currentLine = '';
(operationData.text as string).split('\n').forEach((textLine: string) => {
textLine.split(' ').forEach((textPart: string) => {
if (
currentLine.length + textPart.length + 1 >
(operationData.lineLength as number)
) {
lines.push(currentLine.trim());
currentLine = `${textPart} `;
return;
}
currentLine += `${textPart} `;
});
lines.push(currentLine.trim());
currentLine = '';
});
// Combine the lines to a single string
// gm escapes `"` internally, but doesn't do it for `\`
const renderText = lines.join('\n').replaceAll('\\', '\\\\');
const fonts = await getSystemFonts();
let font = (options.font || operationData.font) as string | undefined;
if (!font) {
font = fonts.find((systemFont) => systemFont.includes('Arial.'));
}
if (!font) {
throw new NodeOperationError(
this.getNode(),
'Default font not found. Select a font from the options.',
);
}
if (!fonts.includes(font)) {
throw new NodeOperationError(
this.getNode(),
'The selected font is not available. Select a font from the options.',
);
}
const nodeVersion = this.getNode().typeVersion;
const gravity =
nodeVersion >= 1.1
? resolveGravity(
operationData.horizontalAlignment as string,
operationData.verticalAlignment as string,
)
: 'northwest';
gmInstance = gmInstance!
.fill(operationData.fontColor as string)
.fontSize(operationData.fontSize as number)
.font(font)
.drawText(
operationData.positionX as number,
operationData.positionY as number,
renderText,
gravity,
);
} else if (operationData.operation === 'transparent') {
gmInstance = gmInstance!.transparent(operationData.color as string);
}
}
if (item.binary !== undefined && newItem.binary) {
// Create a shallow copy of the binary data so that the old
// data references which do not get changed still stay behind
// but the incoming data does not get changed.
Object.assign(newItem.binary, item.binary);
// Make a deep copy of the binary data we change
if (newItem.binary[binaryPropertyName]) {
newItem.binary[binaryPropertyName] = deepCopy(newItem.binary[binaryPropertyName]);
}
}
if (newItem.binary![binaryPropertyName] === undefined) {
newItem.binary![binaryPropertyName] = {
data: '',
mimeType: '',
};
}
if (options.quality !== undefined) {
gmInstance = gmInstance!.quality(options.quality as number);
}
if (options.format !== undefined) {
const format = validateImageFormat(options.format, this.getNode());
gmInstance = gmInstance!.setFormat(format);
newItem.binary![binaryPropertyName].fileExtension = options.format as string;
newItem.binary![binaryPropertyName].mimeType = `image/${options.format}`;
const fileName = newItem.binary![binaryPropertyName].fileName;
if (fileName?.includes('.')) {
newItem.binary![binaryPropertyName].fileName =
fileName.split('.').slice(0, -1).join('.') + '.' + options.format;
}
}
if (options.fileName !== undefined) {
newItem.binary![binaryPropertyName].fileName = options.fileName as string;
}
returnData.push(
await new Promise<INodeExecutionData>((resolve, reject) => {
gmInstance.toBuffer(async (error: Error | null, buffer: Buffer) => {
cleanupFunctions.forEach(async (cleanup) => cleanup());
if (error) {
return reject(error);
}
const binaryData = await this.helpers.prepareBinaryData(Buffer.from(buffer));
newItem.binary![binaryPropertyName] = {
...newItem.binary![binaryPropertyName],
...binaryData,
};
return resolve(newItem);
});
}),
);
} catch (error) {
if (this.continueOnFail()) {
returnData.push({
json: {
error: error.message,
},
pairedItem: {
item: itemIndex,
},
});
continue;
}
throw error;
}
}
return [returnData];
return await router.call(this);
}
}
File diff suppressed because it is too large. Load diff
@@ -257,7 +257,7 @@ describe('Edit Image v2', () => {
expect(editImage.description.defaultVersion).toBe(2);
});
it('shows a deprecation notice only on versions below 2', () => {
it('shows an unsupported-version notice only on versions below 2', () => {
const editImage = new EditImage();
const notice = editImage.description.properties.find(
(property) => property.name === 'legacyVersionNotice',
@@ -271,7 +271,7 @@ describe('Edit Image v2', () => {
},
},
});
expect(notice?.displayName).toContain('deprecated');
expect(notice?.displayName).toContain('no longer supported');
expect(notice?.displayName).toContain('version 2');
});
-2
View File
@@ -902,7 +902,6 @@
"@types/aws4": "^1.5.1",
"@types/basic-auth": "catalog:",
"@types/express": "catalog:",
"@types/gm": "^1.25.0",
"@types/html-to-text": "^9.0.1",
"@types/js-nacl": "^1.3.0",
"@types/jsdom": "catalog:",
@@ -976,7 +975,6 @@
"fflate": "catalog:",
"form-data": "catalog:",
"get-system-fonts": "2.0.2",
"gm": "1.25.1",
"html-to-text": "9.0.5",
"iconv-lite": "catalog:",
"ics": "2.40.0",
-42
View File
@@ -8120,9 +8120,6 @@ importers:
get-system-fonts:
specifier: 2.0.2
version: 2.0.2
gm:
specifier: 1.25.1
version: 1.25.1(supports-color@8.1.1)
html-to-text:
specifier: 9.0.5
version: 9.0.5
@@ -8316,9 +8313,6 @@ importers:
'@types/express':
specifier: 'catalog:'
version: 5.0.1
'@types/gm':
specifier: ^1.25.0
version: 1.25.0
'@types/html-to-text':
specifier: ^9.0.1
version: 9.0.4
@@ -15900,9 +15894,6 @@ packages:
'@types/glob@8.0.0':
resolution: {integrity: sha512-l6NQsDDyQUVeoTynNpC9uRvCUint/gSUXQA2euwmTuWGvPY5LSDUu6tkCtJB2SvGQlJQzLaKqcGZP4//7EDveA==}
'@types/gm@1.25.0':
resolution: {integrity: sha512-y0nI4vp+0Vtsve+daADIHeSckm11TnWAdC4CBq2BEXTg+CfJiolnsnzsXeIEuIpBCksjN26LUZlvQKJDpthw5g==}
'@types/har-format@1.2.16':
resolution: {integrity: sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==}
@@ -17387,15 +17378,6 @@ packages:
resolution: {integrity: sha512-FmeCCAenzH0KH381SPT5FZmiA/TmpndpcaShhfgEN9eCVjnFBqq3l1xrI42y8+PPLI6hypzou4GXw00WHmPBLQ==}
engines: {node: '>= 0.4'}
array-iterate@2.0.1:
resolution: {integrity: sha512-I1jXZMjAgCMmxT4qxXfPXa6SthSoE8h6gkSI9BGGNv8mP8G/v0blc+qFnZu6K42vTOiuME596QaLO0TP3Lk0xg==}
array-parallel@0.1.3:
resolution: {integrity: sha512-TDPTwSWW5E4oiFiKmz6RGJ/a80Y91GuLgUYuLd49+XBS75tYo8PNgaT2K/OxuQYqkoI852MDGBorg9OcUSTQ8w==}
array-series@0.1.5:
resolution: {integrity: sha512-L0XlBwfx9QetHOsbLDrE/vh2t018w9462HM3iaFfxRiK83aJjAt/Ja3NMkOW7FICwWTlQBa3ZbL5FKhuQWkDrg==}
array-union@2.1.0:
resolution: {integrity: sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==}
engines: {node: '>=8'}
@@ -20136,11 +20118,6 @@ packages:
globjoin@0.1.4:
resolution: {integrity: sha512-xYfnw62CKG8nLkZBfWbhWwDw02CHty86jfPcc2cr3ZfeuK9ysoVPPEUxf21bAD/rWAgk52SuBrLJlefNy8mvFg==}
gm@1.25.1:
resolution: {integrity: sha512-jgcs2vKir9hFogGhXIfs0ODhJTfIrbECCehg38tqFgHm8zqXx7kAJyCYAFK4jTjx71AxrkFtkJBawbAxYUPX9A==}
engines: {node: '>=14'}
deprecated: The gm module has been sunset. Please migrate to an alternative. https://github.com/aheckmann/gm?tab=readme-ov-file#2025-02-24-this-project-is-not-maintained
gonzales-pe@4.3.0:
resolution: {integrity: sha512-otgSPpUmdWJ43VXyiNgEYE4luzHCL2pz4wQ0OnDluC6Eg4Ko3Vexy/SrSynglw/eR+OhkzmqFCZa/OFa/RgAOQ==}
engines: {node: '>=0.6.0'}
@@ -34586,10 +34563,6 @@ snapshots:
'@types/minimatch': 5.1.2
'@types/node': 20.19.41
'@types/gm@1.25.0':
dependencies:
'@types/node': 20.19.41
'@types/har-format@1.2.16': {}
'@types/hast@3.0.5':
@@ -36228,12 +36201,6 @@ snapshots:
is-string: 1.1.1
math-intrinsics: 1.1.0
array-iterate@2.0.1: {}
array-parallel@0.1.3: {}
array-series@0.1.5: {}
array-union@2.1.0: {}
array.prototype.findlastindex@1.2.6:
@@ -39611,15 +39578,6 @@ snapshots:
globjoin@0.1.4: {}
gm@1.25.1(supports-color@8.1.1):
dependencies:
array-parallel: 0.1.3
array-series: 0.1.5
cross-spawn: 7.0.6
debug: 3.2.7(supports-color@8.1.1)
transitivePeerDependencies:
- supports-color
gonzales-pe@4.3.0:
dependencies:
minimist: 1.2.8