Over the past couple of weeks, I have been working on a new iOS and Android app using NativeScript. One of the requirements is to compress and upload images. I figured this would be pretty straightforward but couldn’t find any examples of how to accomplish image compression. After some trial and error, I came up with a simple solution that has worked well. Hopefully, this example will save you some time!
The key piece of code is imageSource.saveToFile which takes a third argument that is compressionValue. This allows you to compress the image to a value from 1-100. Check out the playground example below and feel free to ask any questions in the comments below.
var saved = imageSource.saveToFile(path, "jpg", compressionValue);