trim function Null safety

Image trim(
  1. Image src,
  2. {TrimMode mode = TrimMode.transparent,
  3. Trim sides = Trim.all}

Automatically crops the image by finding the corners of the image that meet the mode criteria (not transparent or a different color).

mode can be either TrimMode.transparent, TrimMode.topLeftColor or TrimMode.bottomRightColor.

sides can be used to control which sides of the image get trimmed, and can be any combination of, Trim.bottom, Trim.left, and Trim.right.


Image trim(Image src,
    {TrimMode mode = TrimMode.transparent, Trim sides = Trim.all}) {
  if (mode == TrimMode.transparent && src.channels == Channels.rgb) {
    return Image.from(src);

  final crop = findTrim(src, mode: mode, sides: sides);

  final dst = Image(crop[2], crop[3], exif: src.exif, iccp: src.iccProfile);

  copyInto(dst, src,
      srcX: crop[0], srcY: crop[1], srcW: crop[2], srcH: crop[3], blend: false);

  return dst;