Skip to content

Commit 37bfc53

Browse files
authored
Add the ability to parse workflows from AVIF images (#4420)
1 parent b240c09 commit 37bfc53

File tree

7 files changed

+486
-3
lines changed

7 files changed

+486
-3
lines changed

browser_tests/assets/workflow.avif

25.4 KB
Binary file not shown.

browser_tests/tests/loadWorkflowInMedia.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ test.describe('Load Workflow in Media', () => {
1515
'workflow.mp4',
1616
'workflow.mov',
1717
'workflow.m4v',
18-
'workflow.svg'
18+
'workflow.svg',
19+
'workflow.avif'
1920
]
2021
fileNames.forEach(async (fileName) => {
2122
test(`Load workflow in ${fileName} (drop from filesystem)`, async ({

src/constants/supportedWorkflowFormats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* All supported image formats that can contain workflow data
77
*/
88
export const IMAGE_WORKFLOW_FORMATS = {
9-
extensions: ['.png', '.webp', '.svg'],
10-
mimeTypes: ['image/png', 'image/webp', 'image/svg+xml']
9+
extensions: ['.png', '.webp', '.svg', '.avif'],
10+
mimeTypes: ['image/png', 'image/webp', 'image/svg+xml', 'image/avif']
1111
}
1212

1313
/**

src/scripts/app.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { deserialiseAndCreate } from '@/utils/vintageClipboard'
8080
import { type ComfyApi, PromptExecutionError, api } from './api'
8181
import { defaultGraph } from './defaultGraph'
8282
import {
83+
getAvifMetadata,
8384
getFlacMetadata,
8485
getLatentMetadata,
8586
getPngMetadata,
@@ -1351,6 +1352,16 @@ export class ComfyApp {
13511352
} else {
13521353
this.showErrorOnFileLoad(file)
13531354
}
1355+
} else if (file.type === 'image/avif') {
1356+
const { workflow, prompt } = await getAvifMetadata(file)
1357+
1358+
if (workflow) {
1359+
this.loadGraphData(JSON.parse(workflow), true, true, fileName)
1360+
} else if (prompt) {
1361+
this.loadApiJson(JSON.parse(prompt), fileName)
1362+
} else {
1363+
this.showErrorOnFileLoad(file)
1364+
}
13541365
} else if (file.type === 'image/webp') {
13551366
const pngInfo = await getWebpMetadata(file)
13561367
// Support loading workflows from that webp custom node.

0 commit comments

Comments
 (0)