resizeImage static method

List<int> resizeImage(
  1. Uint8List bytes, {
  2. int newWidth = 100,
  3. int? longestSizeTo,
})

Implementation

static List<int> resizeImage(Uint8List bytes,
    {int newWidth = 100, int? longestSizeTo}) {
  Image image = decodeWithCheck(bytes);

  Image thumbnail;
  if (longestSizeTo != null) {
    if (image.width > image.height) {
      thumbnail = copyResize(
        image,
        width: longestSizeTo,
      );
    } else {
      thumbnail = copyResize(
        image,
        height: longestSizeTo,
      );
    }
  } else {
    thumbnail = copyResize(
      image,
      width: newWidth,
    );
  }
  var encoded = encodeJpg(thumbnail);
  return encoded;
}