Skip to content

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

Open
@manthan-l-simformsolutions

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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