Skip to content

Slow #215

Open
Open
Slow#215
@jacobg

Description

@jacobg

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
    )
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions