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

System is hanging when we are trying to load 30 images of 100MB size. #219

Open
manthan-l-simformsolutions opened this issue May 11, 2024 · 0 comments

Comments

@manthan-l-simformsolutions

issue:- The system is experiencing performance issues when attempting to load 30 images, each with a size of 100MB. after all, we have attempted compression in one file at a time in the loop but that is also hanging the system.

Here I have attached some example code that we are using.

const imageSize = (file) => {
    const reader = new FileReader()
    reader.readAsDataURL(file)
    const promise = new Promise((resolve, reject) => {
      reader.onload = function (e) {
        const image = new Image()

        image.src = e.target.result

        image.onload = function () {
          const height = this.height
          const width = this.width

          resolve({ width, height })
        }

        image.onerror = reject
      }
    })

    return promise
  }

 const compressImage = async (file) => {
    const imageDimensions = await imageSize(file)
    const options = {
      maxSizeMB: 1,
      maxWidthOrHeight:
        imageDimensions?.width > 1300 ? 1300 : imageDimensions?.width,
      useWebWorker: true,
    }

    const compressedImg = await imageCompression(file, options)

    return compressedImg
  }

const totalImages = imageFiles.length
for (let i = 0; i < totalImages; i++) {
      const file = imageFiles[i].image.originFileObj
      const timeStamp = new Date().valueOf()
      const compressedImageFile = await compressImage(toJS(file))
}

How can I compress images without hanging a system? any suggestion would be appreciated. thanks

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