dlemstra / magick-wasm

The WASM library for ImageMagick

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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)

Screenshot from 2024-04-06 12-22-17

Output of Failed Image processing (more than 4-5mb size)

Screenshot from 2024-04-06 12-27-39

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

  1. Following this disucssion to create dedicated worker, browser based only #112

  2. 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.