Skip to content

Commit

Permalink
fix(Edit Image Node): Fix Text operation by setting Arial as default …
Browse files Browse the repository at this point in the history
…font (#11125)

Co-authored-by: Shireen Missi <[email protected]>
  • Loading branch information
ayatnkw and ShireenMissi authored Nov 1, 2024
1 parent 63efefc commit 60c1ace
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/nodes-base/nodes/EditImage/EditImage.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 <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>.',
},
],
},
Expand Down Expand Up @@ -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 <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',
Expand Down Expand Up @@ -951,7 +951,6 @@ export class EditImage implements INodeType {
methods = {
loadOptions: {
async getFonts(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
// @ts-ignore
const files = await getSystemFonts();
const returnData: INodePropertyOptions[] = [];

Expand All @@ -977,11 +976,6 @@ export class EditImage implements INodeType {
return 0;
});

returnData.unshift({
name: 'default',
value: 'default',
});

return returnData;
},
},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 60c1ace

Please sign in to comment.