Sharp(data.Body)
.resize(imageWidth, imageHeight)
(.max()<- this should be optional, for ex: if nocrop == true)
.toFormat(imageFormat)
.toBuffer()
I think this is pretty much your only option:
var sharpInstance = Sharp(data.Body)
.resize(imageWidth, imageHeight);
if (nocrop) {
sharpInstance = sharpInstance.max();
}
sharpInstance
.toFormat(imageFormat)
.toBuffer();
If it absolutely has to be a single chain then the following is untested but will probably work:
Sharp(data.Body)
.resize(imageWidth, imageHeight)
[nocrop ? 'max' : 'crop']()
.toFormat(imageFormat)
.toBuffer()
...but please use @papandreou's suggestion for more easily maintained code :)
Most helpful comment
I think this is pretty much your only option: