Skip to content

Instantly share code, notes, and snippets.

@earlgreyxxx
Last active September 15, 2021 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save earlgreyxxx/3c173cb7dd802ce204148a040deea945 to your computer and use it in GitHub Desktop.
Save earlgreyxxx/3c173cb7dd802ce204148a040deea945 to your computer and use it in GitHub Desktop.
/**************************************************************************
* 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