imageResize static method

Uint8List imageResize({
  1. required Uint8List bytes,
  2. int? maxHeight,
  3. int? maxWidth,
})

Implementation

static Uint8List imageResize({required Uint8List bytes, int? maxHeight, int? maxWidth}) {
  var imageIsPng = isPng(bytes);
  img.Image originalImage = img.decodeImage(bytes)!;
  img.Image fixedImage = img.copyResize(interpolation: img.Interpolation.average, originalImage, height: maxHeight, width: maxWidth, maintainAspect: true);
  if (imageIsPng) {
    return img.encodePng(fixedImage);
  } else {
    return img.encodeJpg(quality: 75, fixedImage);
  }
}