addTextWatermarkCentered static method

  1. @Deprecated('Use addTextWatermark with [dstX] and [dstY] as null instead')
Future<Uint8List> addTextWatermarkCentered({
  1. required Uint8List imgBytes,
  2. required String watermarkText,
  3. BitmapFont? font,
  4. Color color = Colors.black,
})

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

await addTextWatermarkCentered(
  imgBytes : //Image converted to Uint8List
  watermarkText: //The text
  font: //Text font type (default arial_48)
  color: //Text color (default black)
);

Implementation

@Deprecated('Use addTextWatermark with [dstX] and [dstY] as null instead')
static Future<Uint8List> addTextWatermarkCentered({
  ///Image converted to Uint8List
  required Uint8List imgBytes,

  ///The text
  required String watermarkText,

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

  ///Text color (default black)
  Color color = Colors.black,
}) async {
  ///Original Image
  final originalImage = ui.decodeImage(imgBytes)!;

  ///Add Watermark
  ///
  ui.drawString(
    originalImage,
    watermarkText,
    font: font ?? ui.arial48,
    color: _getColor(color),
  );

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

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

  return result;
}