fix(Edit Image Node): Fix Text operation by setting Arial as default font (#11125)
Some checks failed
Test Master / install-and-build (push) Has been cancelled
Test Master / Unit tests (18.x) (push) Has been cancelled
Test Master / Unit tests (20.x) (push) Has been cancelled
Test Master / Unit tests (22.4) (push) Has been cancelled
Test Master / Lint (push) Has been cancelled
Test Master / Notify Slack on failure (push) Has been cancelled

Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com>
This commit is contained in:
aya 2024-11-01 18:49:48 +02:00 committed by GitHub
parent 63efefcd24
commit 60c1ace64b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,7 +10,7 @@ import type {
INodeType, INodeType,
INodeTypeDescription, INodeTypeDescription,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { NodeConnectionType, deepCopy } from 'n8n-workflow'; import { NodeOperationError, NodeConnectionType, deepCopy } from 'n8n-workflow';
import gm from 'gm'; import gm from 'gm';
import { file } from 'tmp-promise'; import { file } from 'tmp-promise';
import getSystemFonts from 'get-system-fonts'; import getSystemFonts from 'get-system-fonts';
@ -849,9 +849,9 @@ export class EditImage implements INodeType {
typeOptions: { typeOptions: {
loadOptionsMethod: 'getFonts', loadOptionsMethod: 'getFonts',
}, },
default: 'default', default: '',
description: description:
'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.', 'The font to use. Defaults to Arial. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
}, },
], ],
}, },
@ -890,9 +890,9 @@ export class EditImage implements INodeType {
typeOptions: { typeOptions: {
loadOptionsMethod: 'getFonts', loadOptionsMethod: 'getFonts',
}, },
default: 'default', default: '',
description: description:
'The font to use. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.', 'The font to use. Defaults to Arial. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code/expressions/">expression</a>.',
}, },
{ {
displayName: 'Format', displayName: 'Format',
@ -951,7 +951,6 @@ export class EditImage implements INodeType {
methods = { methods = {
loadOptions: { loadOptions: {
async getFonts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> { async getFonts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
// @ts-ignore
const files = await getSystemFonts(); const files = await getSystemFonts();
const returnData: INodePropertyOptions[] = []; const returnData: INodePropertyOptions[] = [];
@ -977,11 +976,6 @@ export class EditImage implements INodeType {
return 0; return 0;
}); });
returnData.unshift({
name: 'default',
value: 'default',
});
return returnData; return returnData;
}, },
}, },
@ -1234,15 +1228,23 @@ export class EditImage implements INodeType {
// Combine the lines to a single string // Combine the lines to a single string
const renderText = lines.join('\n'); const renderText = lines.join('\n');
const font = options.font || operationData.font; let font = (options.font || operationData.font) as string | undefined;
if (!font) {
const fonts = await getSystemFonts();
font = fonts.find((_font) => _font.includes('Arial.'));
}
if (font && font !== 'default') { if (!font) {
gmInstance = gmInstance!.font(font as string); throw new NodeOperationError(
this.getNode(),
'Default font not found. Select a font from the options.',
);
} }
gmInstance = gmInstance! gmInstance = gmInstance!
.fill(operationData.fontColor as string) .fill(operationData.fontColor as string)
.fontSize(operationData.fontSize as number) .fontSize(operationData.fontSize as number)
.font(font as string)
.drawText( .drawText(
operationData.positionX as number, operationData.positionX as number,
operationData.positionY as number, operationData.positionY as number,