react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

Different file size from the resized file to the uploaded file.

Open immortalx opened this issue 6 years ago • 12 comments

The original file is 11Mb so its resizing and compressing for sure.

The resized file is correctly generated in the cache directory, the response object reports the correct size of 147kb. The uploaded file ends up with 506kb. I've tried on my local server and on s3 and the file size is the same, 506kb.

I've double checked and the file exists in the system with the correct size.

Am i doing something wrong here? Do i need to set the output path or something like that?

Thank you

immortalx avatar May 04 '18 10:05 immortalx

@immortalx Can you learn from your code? My image compression is a bit problematic, the original size is 6M, can only be compressed to 500kb, how do you compress to 100kb?

qqdayan avatar May 10 '18 12:05 qqdayan

@qqdayan i set the quality to 76, but it will also depend on maxWidth and maxHeight.

immortalx avatar May 11 '18 10:05 immortalx

I have the same problem. My uploaded files are 3-4 times the size of the response after resizing, regardless of whether I upload from response.uri or response.path. I'm using an iPhone X to upload, so I'm wondering if it has something to do with the new HEIF format.

noll-fyra avatar May 31 '18 05:05 noll-fyra

@4ian Are we doing something wrong here or it's some kind of incompatibility with the latest version of RN?

immortalx avatar May 31 '18 18:05 immortalx

@immortalx thanks,Picture returned is not a kilobyte,I understand the mistake.

qqdayan avatar Jun 01 '18 01:06 qqdayan

I have the same question.@noll-fyra . I compress file the less than 1M ,but I upload the file is more than 1M.

MHwishes avatar Aug 04 '18 08:08 MHwishes

Can anyone tell me how to use this library? I just need to reduce the size of the image. My code looks like: ImageResizer.createResizedImage( uri, <-- uri of the image from local storage(using CameraRoll) width, <-- got from Image.getSize() height, <-- got from Image.getSize() 'JPEG', 0, ).then((response) => { }).catch((err) => { console.log('image compression error: ', err); // Oops, something went wrong. Check that the filename is correct and // inspect err to get more details. });

ajaykumar97 avatar Dec 20 '18 09:12 ajaykumar97

I was facing the same issue.

Solved it with adding ../tmp as the outputPath, which seems to be a better directory for this anyway.

EthanDM avatar Sep 16 '19 00:09 EthanDM

@EthanDM @immortalx Can you share some minimal sample code on how you worked arround this bug?

Did you try any alternative? @bamlab do you have any clue or suggestions regarding this?

rupinderjeet avatar Feb 27 '20 04:02 rupinderjeet

Sure, here is a utility wrapper I made for it:

import RnImageResizer, { Response } from 'react-native-image-resizer'

const ImageResizer = async ({
  path,
  maxWidth = 1080,
  maxHeight = 1080,
  quality = 75,
  compressFormat = 'JPEG',
  rotation = 0,
  outputPath = '../tmp'
}: {
  path: string
  maxWidth?: number
  maxHeight?: number
  quality?: number
  compressFormat?: 'PNG' | 'JPEG' | 'WEBP'
  rotation?: number
  outputPath?: string
}) => {
  return new Promise(resolve => {
    RnImageResizer.createResizedImage(
      path,
      maxWidth,
      maxHeight,
      compressFormat,
      quality,
      rotation,
      outputPath
    ).then((res: Response) => resolve(res))
  })
}

export { ImageResizer }

EthanDM avatar Feb 27 '20 05:02 EthanDM

Thank you.

rupinderjeet avatar Mar 02 '20 15:03 rupinderjeet

Any further progress on this? Issue still present and tried ‘../tmp’ fix didn’t work for me

chris44f avatar Dec 10 '20 11:12 chris44f

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 18:09 stale[bot]

This issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Sep 08 '22 18:09 stale[bot]