Skip to content

Instantly share code, notes, and snippets.

@Jagathishrex
Created April 22, 2020 03:07
Show Gist options
  • Select an option

  • Save Jagathishrex/b58db65193c71d8f85d6b5e20b94495c to your computer and use it in GitHub Desktop.

Select an option

Save Jagathishrex/b58db65193c71d8f85d6b5e20b94495c to your computer and use it in GitHub Desktop.
// image as dataURL
let jpeg = canvas.toDataURL('image/jpg'); // 0.92
let webp = canvas.toDataURL('image/webp', 0.5);
//zip
let jsZip = new JSZip();
let folder = jsZip.folder("images");
let baseString = getBase64String(jpeg);
folder.file("image1.jpeg", baseString, {base64 : true});
let baseString2 = getBase64String(webp);
folder.file("image2.webp", baseString2, {base64 : true});
Generate the zip file
zip.generateAsync({type:"blob"}).then(function (content) {
content = URL.createObjectURL(content);
let name = `JSJeep.zip`;
download(content, name); // already written above
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment