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. To test a string first use this MD5 hash generator tool to convert the string to an MD5 hash. Then check out the playground example below and feel free to ask any questions in the comments below.
var saved = imageSource.saveToFile(path, "jpg", compressionValue);
Demo
Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LY, Weather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.
life saver, thanks