How to compress image size without effecting image quality? how can i create a function that take a image permater of a imageuri and then compress that image? I am using react native cli with Nodejs
How can i get this size
image: {
width: ‘130%’,
aspectRatio: 1,
height: 600,
}
3
Answers
Well It's possible to compress the image without affecting image quality I found this package name react-native-image-resizer that I used to do that now my 3MB image is now 50kb only
You can use npm module
sharp
. Try this code.Besides this, inside
resize
method you can use more parameters such asfit
,position
,background
etc.Please take a look at this article https://www.digitalocean.com/community/tutorials/how-to-process-images-in-node-js-with-sharp
Hope this helps you.
Since you are using react native I would suggest to use react-native-compressor
Then in the code you can do
Where
uri
is the path to your image. Here are some examples of how the auto compression method works. You can also do manual compressions and can check the NPM package documentation for more info.