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