I'm using FilePond and Doka for managing and editing image uploads on a form with unique needs, and I am hoping to be able to resize and/or compress images automatically when a file is added to FilePond.
I'm using the React implementation of FilePond + Doka.
Image resizing and compression has been configured, and are working when a user edits an image and then hits 'Done' so it's clear that things are wired up correctly.
In our use case, we're not so concerned about the quality and resolution of the resulting images, but we're doing a lot of custom file management on the client size using IndexedDB and LocalStorage. Most user images won't be edited/marked up manually by users, so we'd like to be able to resize and compress manually before opening a transaction and pushing to IndexedDB.
I've tried to use filePond.current.processFiles() and find that everything runs, but the file size doesn't appear to change and this processing function also initiates a file upload.
// Imports
import { FilePond, registerPlugin } from "react-filepond"
import FilePondPluginImageEdit from "filepond-plugin-image-edit"
import FilePondPluginImageExifOrientation from "filepond-plugin-image-exif-orientation"
import FilePondPluginImagePreview from "filepond-plugin-image-preview"
import FilePondPluginFileEncode from "filepond-plugin-file-encode"
import FilePondPluginImageTransform from "filepond-plugin-image-transform"
import FilePondPluginImageResize from "filepond-plugin-image-resize"
import * as Doka from "../../scripts/react-doka/lib/doka.esm.min"
// Register FilePond plugins
registerPlugin(
FilePondPluginImageEdit,
FilePondPluginImageExifOrientation,
FilePondPluginImagePreview,
FilePondPluginFileEncode,
FilePondPluginImageTransform,
FilePondPluginImageResize
)
// Component
<FilePond
ref={filePond}
files={photoFiles}
allowImageEdit={true}
allowMultiple={true}
maxFiles={10}
allowImageExifOrientation={true}
allowImageResize={true}
imageResizeTargetWidth={800}
imageResizeTargetHeight={800}
imageResizeMode={"contain"}
instantUpload={false}
disabled={isDisabled}
allowDrop={!isDisabled}
allowBrowse={!isDisabled}
labelIdle={cameraButton}
server="api/"
onupdatefiles={fileItems => {
updateFiles(fileItems.map(fileItem => fileItem.file))
}}
imageEditEditor={
(DokaInstance = Doka.create({
utils: ["crop", "markup"],
markupAllowAddMarkup: true,
markupColorDefault: 3,
outputData: true, //Output the modifications made as an object representing the changes
outputStripImageHead: false, // exif data
outputQuality: 75,
outputWidth: 800,
outputHeight: 800,
outputFit: "contain",
onconfirm: output => {
handleDokaConfirm(output)
},
}))
}
/>```