From 60c1ace64be29d651ce7b777fbb576598e38b9d7 Mon Sep 17 00:00:00 2001 From: aya <15815271+ayatnkw@users.noreply.github.com> Date: Fri, 1 Nov 2024 18:49:48 +0200 Subject: [PATCH] fix(Edit Image Node): Fix Text operation by setting Arial as default font (#11125) Co-authored-by: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com> --- .../nodes/EditImage/EditImage.node.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/nodes-base/nodes/EditImage/EditImage.node.ts b/packages/nodes-base/nodes/EditImage/EditImage.node.ts index 3e4544de8e..0cfc6b0bcd 100644 --- a/packages/nodes-base/nodes/EditImage/EditImage.node.ts +++ b/packages/nodes-base/nodes/EditImage/EditImage.node.ts @@ -10,7 +10,7 @@ import type { INodeType, INodeTypeDescription, } from 'n8n-workflow'; -import { NodeConnectionType, deepCopy } from 'n8n-workflow'; +import { NodeOperationError, NodeConnectionType, deepCopy } from 'n8n-workflow'; import gm from 'gm'; import { file } from 'tmp-promise'; import getSystemFonts from 'get-system-fonts'; @@ -849,9 +849,9 @@ export class EditImage implements INodeType { typeOptions: { loadOptionsMethod: 'getFonts', }, - default: 'default', + default: '', description: - 'The font to use. Choose from the list, or specify an ID using an expression.', + 'The font to use. Defaults to Arial. Choose from the list, or specify an ID using an expression.', }, ], }, @@ -890,9 +890,9 @@ export class EditImage implements INodeType { typeOptions: { loadOptionsMethod: 'getFonts', }, - default: 'default', + default: '', description: - 'The font to use. Choose from the list, or specify an ID using an expression.', + 'The font to use. Defaults to Arial. Choose from the list, or specify an ID using an expression.', }, { displayName: 'Format', @@ -951,7 +951,6 @@ export class EditImage implements INodeType { methods = { loadOptions: { async getFonts(this: ILoadOptionsFunctions): Promise { - // @ts-ignore const files = await getSystemFonts(); const returnData: INodePropertyOptions[] = []; @@ -977,11 +976,6 @@ export class EditImage implements INodeType { return 0; }); - returnData.unshift({ - name: 'default', - value: 'default', - }); - return returnData; }, }, @@ -1234,15 +1228,23 @@ export class EditImage implements INodeType { // Combine the lines to a single string 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') { - gmInstance = gmInstance!.font(font as string); + if (!font) { + throw new NodeOperationError( + this.getNode(), + 'Default font not found. Select a font from the options.', + ); } gmInstance = gmInstance! .fill(operationData.fontColor as string) .fontSize(operationData.fontSize as number) + .font(font as string) .drawText( operationData.positionX as number, operationData.positionY as number,