Fails with Images with more than 5MB with Dedicated Worker
abduljabbar021 opened this issue · comments
magick-wasm version
0.0.28
Description
When trying to adjust the quality of any image with more than 4-5mb, it fails.
Output of Successful Image processing (below 4-5mb size)
Output of Failed Image processing (more than 4-5mb size)
here is very basic code from Dedicated Worker
wk.onmessage = async function(event){
const response = await fetch(event.data.source);
const buffer = await response.arrayBuffer();
const data = new Uint8Array(buffer);
entireMagickLibrary.ImageMagick.read(data, image => {
image.quality = 5;
image.write(entireMagickLibrary.MagickFormat.Jpeg, data => {
wk.postMessage(data);
});
});
};
wk.postMessage({ init: true });
Rest of the code is similar to this https://github.com/dlemstra/magick-wasm/discussions/112
I tried setting image quality between 5-80 but it always fail if image size is larger than 4-5mb
Steps to Reproduce
-
Following this disucssion to create dedicated worker, browser based only #112
-
Adjust Image Quality and it fails where image size is larger than 4-5mb
Images
No response
The size of the input image is not relevant. I suspect this happens when the width/height of the image is large. And because of that you seem to be running out of memory at some point. Because wasm is 32-bit you will run out of memory much fast than on a 64-bit platform. In the future there will probably be support for 64-bit web assembly but until then you will have a low memory limit.
Well! in that case what options do I have for large images? Because my main objective is to compress the size and quality of large images.
There are no options? There is a memory limit and you are running into that limit.
Did you try to use IndexDB storage processed images?
I have processed more than 200 images. That is OK.
This is my repo.
Did you try to use IndexDB storage processed images? I have processed more than 200 images. That is OK. This is my repo.
@julenwang thank you for you suggestion. My actual target was to resize images before uploading therefore, I had to move with https://github.com/nodeca/pica which is a really amazing library.