resizeImage static method
Implementation
static Future<http.MultipartFile?> resizeImage(File? imgSrc,
{int w = 400, int h = 400, String fieldName = 'file'}) async {
try {
if (imgSrc == null) return null;
Img.Image? image_temp = Img.decodeImage(imgSrc.readAsBytesSync());
if (image_temp == null) return null;
Img.Image resized_img = Img.copyResize(image_temp, width: w);
var multipartFile = new http.MultipartFile.fromBytes(
'$fieldName',
Img.encodeJpg(resized_img),
filename: '${imgSrc.path}'.replaceAll('/', '_') + '.jpg',
);
return multipartFile;
} catch (e) {
print('${e}');
return null;
}
}