Skip to content

Commit 87f0617

Browse files
committed
primitive convert from png -> jpg worked
1 parent 6237fb4 commit 87f0617

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

index.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ <h1>Offline Image Converter</h1>
135135

136136
// TODO output type should match media type
137137
function downloadImage(imageData, fileName, outputType) {
138-
const blob = new Blob([pdf], { type: outputType });
138+
const blob = new Blob([imageData], { type: outputType });
139139
const url = URL.createObjectURL(blob);
140140
const a = document.createElement('a');
141141
a.href = url;
@@ -173,7 +173,7 @@ <h1>Offline Image Converter</h1>
173173
}
174174

175175
if (type === "done") {
176-
downloadPdf(imageData, fileName, outputType);
176+
downloadImage(imageData, fileName, outputType);
177177
} else if (type === "error") {
178178
showError(message);
179179
}
@@ -206,9 +206,11 @@ <h1>Offline Image Converter</h1>
206206
// TODO remove dot from filename if present
207207
const fileName = file.name;
208208
const inputType = "png";
209-
const imageData = await file.arrayBuffer();
210-
211-
worker.postMessage({ imageData, fileName, inputType, outputType });
209+
const imageDataBuffer = await file.arrayBuffer();
210+
const imageData = new Uint8Array(imageDataBuffer);
211+
const imageTransfer = imageData.buffer;
212+
213+
worker.postMessage({ imageData, fileName, inputType, outputType }, [imageTransfer]);
212214
}
213215
window.convert = convert;
214216

worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ onmessage = async (event) => {
2121
try {
2222
const convertedImage = convert_exposed(imageData, inputType, outputType);
2323

24-
postMessage({ type: "done", imageData: convertedImage, fileName, outputType }, [mergedPdf.buffer]);
24+
postMessage({ type: "done", imageData: convertedImage, fileName, outputType }, [convertedImage.buffer]);
2525
} catch (err) {
2626
if (err instanceof WebAssembly.RuntimeError) {
2727
postMessage({ type: "error", message: "Unexpected WASM exception: " + err.message });

0 commit comments

Comments
 (0)