addTextWatermark static method

Future<Uint8List> addTextWatermark({
  1. required Uint8List imgBytes,
  2. required String watermarkText,
  3. int? dstX,
  4. int? dstY,
  5. BitmapFont? font,
  6. Color color = Colors.black,
  7. bool rightJustify = false,
})

This method adds the text that is indicated as a watermark, the parameters are the following:

await addTextWatermark(
  imgBytes : //Image converted to Uint8List
  watermarkText: //The text
  dstX: //X coordinates in the image
  dstY: //Y coordinates in the image
  font: //Text font type (default arial_48)
  color: //Text color (default black)
  rightJustify: //Text right justification (default false)
);

Implementation

static Future<Uint8List> addTextWatermark({
  ///Image converted to Uint8List
  required Uint8List imgBytes,

  ///The text
  required String watermarkText,

  ///X coordinates in the image
  int? dstX,

  ///Y coordinates in the image
  int? dstY,

  ///Text font type
  ui.BitmapFont? font,

  ///Text color
  Color color = Colors.black,

  ///Text right justification
  bool rightJustify = false,
}) async {
  ///Original Image
  final originalImage = ui.decodeImage(imgBytes)!;

  ///Add Watermark
  ui.drawString(
    originalImage,
    watermarkText,
    font: font ?? ui.arial48,
    x: dstX,
    y: dstY,
    color: _getColor(color),
    rightJustify: rightJustify,
  );

  ///Encode image to PNG
  final wmImage = ui.encodePng(originalImage);

  ///Get the result
  final result = Uint8List.fromList(wmImage);

  return result;
}