Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

White space invades image on android phone for the first image taken in camera #178

Open
kyoung-jnn opened this issue Feb 7, 2023 · 9 comments

Comments

@kyoung-jnn
Copy link

Reason

I tried to compress jpeg image, but white space Intermittent occurs..
I think that it is reason of extra canvas. 🙄 how think about it?!

828076ea-f704-4385-8107-f39690b3e8d7_0

Code Example

export const compressImage = async (targetImage: File) => {
  const options = {
    fileType: 'image/jpeg',
    maxSizeMB: 0.5,
    maxIteration: 100,
  };
  try {
    const imageCompression = (await import('browser-image-compression')).default;
    const compressedFile = await imageCompression(targetImage, options);

    return compressedFile;
  } catch (error) {
    console.error(error);
  }
};

const compressedImage = await compressImage(targetImage);
return new File([compressedImage], targetImage.name, {
    type: targetImage.type,
    lastModified: targetImage.lastModified,
});
@kyoung-jnn kyoung-jnn changed the title Unexpected white space invades JPG Image Unexpected white space invades JP(E)G Image Feb 7, 2023
@sscholle
Copy link

sscholle commented Feb 8, 2023

i find this seems to happen when I upload a photo that i took directly with camera (not a file upload) on my Huawei P20 Pro.

In other words: If i choose the upload source to be "Camera" instead of 'File/Browse" in the Android File section dialog.
So if Camera is the source, it them fails to somehow detect the correct image size, and seemingly shrinks down the main image and adds some white border;

@Donaldcwl
Copy link
Owner

Donaldcwl commented Feb 12, 2023

@kyoung-jnn @sscholle
Can you upload the image file as a zip file here so I can reproduce this issue?

Also, can you try it here: https://donaldcwl.github.io/browser-image-compression/example/basic.html

@todevmilen
Copy link

todevmilen commented Mar 17, 2023

New info here ? We have the same problem with Huawei P30 Lite.

@Donaldcwl
Copy link
Owner

Donaldcwl commented Mar 18, 2023

Can someone give detailed steps to reproduce this issue?

lib version, browser, original image file, config, etc

@dyscordia
Copy link

dyscordia commented Apr 3, 2023

Had the same problem. My settings for image compression were:

{ maxSizeMB: 0.5,
maxWidthOrHeight: 1920,
useWebWorker: true }

I found that the combination of maxSize + maxWidthOrHeight caused the image to shrink down in the space, but cause the additional whitespace to appear. I only ever experienced this while using a mobile device camera - never from files from the system.

This was noticed by users on multiple android phones. It seemed to happen frequently on the first image taken, but subsequent images compressed as expected.

I removed the maxWidthOrHeight and that helped resolve the issue.

Hope this helps someone!

@todevmilen
Copy link

@dyscordia Thanks for the advice.

@sscholle
Copy link

sscholle commented May 8, 2023

@kyoung-jnn @sscholle Can you upload the image file as a zip file here so I can reproduce this issue?

Also, can you try it here: https://donaldcwl.github.io/browser-image-compression/example/basic.html

Original
Cannot get it, as it's sent directly to the file element on your sample page.

16835530883031744928381714523776

@sscholle
Copy link

sscholle commented May 8, 2023

Maybe the MB size is the problem.

I tried with a 0.5MB limit, and this gives the bad result with large white border.
Screenshot_20230508_155501

When I choose the bigger size, it seems to work better.
Screenshot_20230508_155237

The images that I used are similar to this one, check resolution and meta data to maybe try replicate.
Screenshot_20230508_160226_com android gallery3d

@Donaldcwl Donaldcwl changed the title Unexpected white space invades JP(E)G Image White space invades image on android phone for the first image taken in camera May 30, 2023
@quique0194
Copy link

This error is so critical for us that we sadly have to migrate to another library: https://github.com/fengyuanchen/compressorjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants