Rollup build

This commit is contained in:
Jake Archibald
2020-11-19 11:00:23 +00:00
parent dfee848a39
commit 56e10b3aa2
340 changed files with 37866 additions and 19153 deletions

View File

@@ -1,13 +1,12 @@
<!doctype html>
<script src='mozjpeg_enc.js'></script>
<script>
const module = mozjpeg_enc();
<!DOCTYPE html>
<script type="module">
import mozjpeg_enc from './mozjpeg_enc.js';
async function loadImage(src) {
// Load image
const img = document.createElement('img');
img.src = src;
await new Promise(resolve => img.onload = resolve);
await new Promise((resolve) => (img.onload = resolve));
// Make canvas same size as image
const canvas = document.createElement('canvas');
[canvas.width, canvas.height] = [img.width, img.height];
@@ -17,7 +16,9 @@
return ctx.getImageData(0, 0, img.width, img.height);
}
module.onRuntimeInitialized = async _ => {
async function main() {
const module = await mozjpeg_enc();
console.log('Version:', module.version().toString(16));
const image = await loadImage('../example.png');
const result = module.encode(image.data, image.width, image.height, {
@@ -39,10 +40,12 @@
chroma_quality: 75,
});
const blob = new Blob([result], {type: 'image/jpeg'});
const blob = new Blob([result], { type: 'image/jpeg' });
const blobURL = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = blobURL;
document.body.appendChild(img);
};
}
main();
</script>