mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Build a demo batch app
This commit is contained in:
BIN
lul/ewag.jpg
Executable file
BIN
lul/ewag.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 25 KiB |
@@ -1,27 +1,67 @@
|
|||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
<style>
|
||||||
<iframe src="http://localhost:8080" width=800 height=800 id="ifr"></iframe>
|
html, body {
|
||||||
<button id="load">Load an image</button>
|
margin: 0;
|
||||||
<button id="extract">extract</button>
|
padding: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
justify-content: flex-start;
|
||||||
|
}
|
||||||
|
header {
|
||||||
|
flex: 0 0;
|
||||||
|
padding: 20px;
|
||||||
|
background-color: #333;
|
||||||
|
}
|
||||||
|
header img {
|
||||||
|
height: 100px;
|
||||||
|
margin: 20px;
|
||||||
|
}
|
||||||
|
iframe {
|
||||||
|
flex: 1 1;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<header id="header">
|
||||||
|
<img src="ewag.jpg">
|
||||||
|
<img src="jakearchibald.jpg">
|
||||||
|
<img src="jasonjmiller.jpg">
|
||||||
|
<img src="kosamari.jpg">
|
||||||
|
<img src="surma.jpg">
|
||||||
|
<button id="apply">Apply right side to all</button>
|
||||||
|
</header>
|
||||||
|
<iframe id="ifr" src="http://localhost:8080"></iframe>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/comlinkjs@3.0.2/umd/comlink.js"></script>
|
<script src="https://cdn.jsdelivr.net/npm/comlinkjs@3.0.2/umd/comlink.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const ifr = document.all.ifr;
|
const ifr = document.all.ifr;
|
||||||
const squoosh = Comlink.proxy(ifr.contentWindow);
|
const squoosh = Comlink.proxy(ifr.contentWindow);
|
||||||
|
|
||||||
async function load() {
|
async function load(url) {
|
||||||
const blob = await fetch("/profile.jpg").then(resp => resp.blob());
|
const blob = await fetch(url).then(resp => resp.blob());
|
||||||
await squoosh.setFile(blob);
|
await squoosh.setFile(blob);
|
||||||
extract();
|
|
||||||
}
|
}
|
||||||
document.all.load.onclick = load;
|
document.all.header.onclick = ev => load(ev.target.src);
|
||||||
|
|
||||||
async function extract() {
|
document.all.apply.onclick = async ev => {
|
||||||
const file = await squoosh.getBlob(1);
|
ev.stopPropagation();
|
||||||
const url = URL.createObjectURL(file);
|
for(const img of document.querySelectorAll("header img")) {
|
||||||
const img = document.createElement('img');
|
await load(img.src);
|
||||||
img.src = url;
|
const file = await squoosh.getBlob(1);
|
||||||
document.body.append(img);
|
const url = URL.createObjectURL(file);
|
||||||
|
downloadFile(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function downloadFile(url) {
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = url;
|
||||||
|
a.download = true;
|
||||||
|
a.hidden = true;
|
||||||
|
document.body.append(a);
|
||||||
|
a.click();
|
||||||
}
|
}
|
||||||
document.all.extract.onclick = extract;
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
BIN
lul/jakearchibald.jpg
Executable file
BIN
lul/jakearchibald.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 MiB |
BIN
lul/jasonjmiller.jpg
Executable file
BIN
lul/jasonjmiller.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
BIN
lul/kosamari.jpg
Executable file
BIN
lul/kosamari.jpg
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 21 KiB |
0
lul/profile.jpg → lul/surma.jpg
Normal file → Executable file
0
lul/profile.jpg → lul/surma.jpg
Normal file → Executable file
|
Before Width: | Height: | Size: 644 KiB After Width: | Height: | Size: 644 KiB |
Reference in New Issue
Block a user