Last active
September 15, 2021 12:25
-
-
Save earlgreyxxx/3c173cb7dd802ce204148a040deea945 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************************** | |
* resize image in file | |
**************************************************************************/ | |
import * as Comlink from "./node_modules/comlink/dist/esm/comlink.min.mjs" | |
export default async function(file,max) | |
{ | |
let canvas = document.createElement('canvas'); | |
let offscreencanvas = canvas.transferControlToOffscreen(); | |
let worker = new Worker("worker.js"); | |
const resize = Comlink.wrap(worker); | |
file = await resize( file, Comlink.transfer(offscreencanvas,[offscreencanvas]), max); | |
// cleanup | |
canvas.remove(); | |
worker.terminate(); | |
return file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment