react-native-image-resizer
react-native-image-resizer copied to clipboard
Different file size from the resized file to the uploaded file.
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 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 i set the quality to 76, but it will also depend on maxWidth and maxHeight.
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.
@4ian Are we doing something wrong here or it's some kind of incompatibility with the latest version of RN?
@immortalx thanks,Picture returned is not a kilobyte,I understand the mistake.
I have the same question.@noll-fyra . I compress file the less than 1M ,but I upload the file is more than 1M.
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. });
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 @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?
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 }
Thank you.
Any further progress on this? Issue still present and tried ‘../tmp’ fix didn’t work for me
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.
This issue has been automatically closed. Thank you for your contributions.