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

Slow #215

Open
jacobg opened this issue Jan 5, 2024 · 0 comments
Open

Slow #215

jacobg opened this issue Jan 5, 2024 · 0 comments

Comments

@jacobg
Copy link

jacobg commented Jan 5, 2024

This library has a very nice specific purpose with a convenient function signature.

However, some feedback in comparing its speed to blueimp-load-image is that browser-image-compression is much slower, e.g., compressing a 6 MB png to 2 MB takes less than a second with blueimp-load-image, whereas it takes around 10 seconds with browser-image-compression.

For reference here is the code in blueimp-load-image to compress to a specific size:

  const image = await loadImage(file, { orientation: true })

  // We reduce by an extra 10%, because for some reason the theoretical compression factor
  // is still a little too high. Maybe there's overhead?
  const compressFactor = Math.sqrt(maxFileSize / file.size) * .9
  const canvas = await loadImage.scale(image.image, {
    maxWidth: image.originalWidth! * compressFactor,
    maxHeight: image.originalHeight! * compressFactor,
    canvas: true })

  return await new Promise<File>(resolve => {
    canvas.toBlob(
      blob => resolve(new File([blob!], file.name, { type: file.type })),
      file.type
    )
  })
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

1 participant