Add User Input Image Support

Users can now supply the --input argument to load their image by default to the application.
This commit is contained in:
blessedcoolant
2022-03-25 07:33:13 +13:00
parent 481e956c3a
commit d0f025f2d4
6 changed files with 56 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
import { useCallback, useEffect, useState } from 'react'
export default function useInputImage() {
const [inputImage, setInputImage] = useState()
const fetchInputImage = useCallback(() => {
fetch('/inputimage')
.then(res => res.blob())
.then(data => {
if (data && data.type.startsWith('image')) {
const userInput = new File([data], 'inputImage')
setInputImage(userInput)
}
})
}, [setInputImage])
useEffect(() => {
fetchInputImage()
}, [])
return inputImage
}