mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
⚡ Add "composite" option to Edit Image Node
This commit is contained in:
parent
b954ec99a3
commit
aaaa804f36
|
@ -52,6 +52,11 @@ export class EditImage implements INodeType {
|
|||
value: 'crop',
|
||||
description: 'Crops the image',
|
||||
},
|
||||
{
|
||||
name: 'Composite',
|
||||
value: 'composite',
|
||||
description: 'Composite image on top of another one',
|
||||
},
|
||||
{
|
||||
name: 'Get Information',
|
||||
value: 'information',
|
||||
|
@ -275,6 +280,53 @@ export class EditImage implements INodeType {
|
|||
},
|
||||
|
||||
|
||||
// ----------------------------------
|
||||
// composite
|
||||
// ----------------------------------
|
||||
{
|
||||
displayName: 'Composite Image Property',
|
||||
name: 'dataPropertyNameComposite',
|
||||
type: 'string',
|
||||
default: '',
|
||||
placeholder: 'data2',
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'The name of the binary property which contains the data of the image to<br />composite on top of image which is found in Property Name.',
|
||||
},
|
||||
{
|
||||
displayName: 'Position X',
|
||||
name: 'positionX',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'X (horizontal) position of composite image.',
|
||||
},
|
||||
{
|
||||
displayName: 'Position Y',
|
||||
name: 'positionY',
|
||||
type: 'number',
|
||||
default: 0,
|
||||
displayOptions: {
|
||||
show: {
|
||||
operation: [
|
||||
'composite',
|
||||
],
|
||||
},
|
||||
},
|
||||
description: 'Y (vertical) position of composite image.',
|
||||
},
|
||||
|
||||
// ----------------------------------
|
||||
// crop
|
||||
// ----------------------------------
|
||||
|
@ -582,6 +634,8 @@ export class EditImage implements INodeType {
|
|||
|
||||
gmInstance = gmInstance.background('transparent');
|
||||
|
||||
const cleanupFunctions: Array<() => void> = [];
|
||||
|
||||
if (operation === 'blur') {
|
||||
const blur = this.getNodeParameter('blur') as number;
|
||||
const sigma = this.getNodeParameter('sigma') as number;
|
||||
|
@ -592,7 +646,23 @@ export class EditImage implements INodeType {
|
|||
const borderColor = this.getNodeParameter('borderColor') as string;
|
||||
|
||||
gmInstance = gmInstance.borderColor(borderColor).border(borderWidth, borderHeight);
|
||||
} else if (operation === 'crop') {
|
||||
} else if (operation === 'composite') {
|
||||
const dataPropertyNameComposite = this.getNodeParameter('dataPropertyNameComposite') as string;
|
||||
const positionX = this.getNodeParameter('positionX') as number;
|
||||
const positionY = this.getNodeParameter('positionY') as number;
|
||||
|
||||
const geometryString = (positionX >= 0 ? '+' : '') + positionX + (positionY >= 0 ? '+' : '') + positionY;
|
||||
|
||||
if (item.binary[dataPropertyNameComposite as string] === undefined) {
|
||||
throw new Error('');
|
||||
}
|
||||
|
||||
const { fd, path, cleanup } = await file();
|
||||
cleanupFunctions.push(cleanup);
|
||||
fsWriteFileAsync(fd, Buffer.from(item.binary![dataPropertyNameComposite as string].data, BINARY_ENCODING));
|
||||
|
||||
gmInstance = gmInstance.composite(path).geometry(geometryString);
|
||||
} else if (operation === 'crop') {
|
||||
const width = this.getNodeParameter('width') as number;
|
||||
const height = this.getNodeParameter('height') as number;
|
||||
|
||||
|
@ -708,6 +778,8 @@ export class EditImage implements INodeType {
|
|||
return new Promise<INodeExecutionData>((resolve, reject) => {
|
||||
gmInstance
|
||||
.toBuffer((error: Error | null, buffer: Buffer) => {
|
||||
cleanupFunctions.forEach(async cleanup => await cleanup());
|
||||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
}
|
||||
|
|
|
@ -498,6 +498,7 @@
|
|||
"rhea": "^1.0.11",
|
||||
"rss-parser": "^3.7.0",
|
||||
"ssh2-sftp-client": "^5.2.1",
|
||||
"tmp-promise": "^3.0.2",
|
||||
"uuid": "^3.4.0",
|
||||
"vm2": "^3.6.10",
|
||||
"xlsx": "^0.16.7",
|
||||
|
|
Loading…
Reference in a new issue