addWaterMarkText method

Future<Image> addWaterMarkText(
  1. String text, {
  2. WMLocation location = WMLocation.tile,
  3. TextStyle style = const TextStyle(),
  4. TextDirection textDirection = TextDirection.ltr,
  5. int? maxLines,
  6. double? minWidth,
  7. double? maxWidth,
  8. double opacity = 0.3,
  9. double sizeScale = 1,
  10. double vOffset = 20,
  11. double hOffset = 20,
  12. double angle = 0,
  13. bool isDispose = false,
})

Image Watermark Extension

Implementation

Future<Image> addWaterMarkText(
  String text, {
  WMLocation location = WMLocation.tile,
  TextStyle style = const TextStyle(),
  TextDirection textDirection = TextDirection.ltr,
  int? maxLines,
  double? minWidth,
  double? maxWidth,
  double opacity = 0.3,
  double sizeScale = 1,
  double vOffset = 20,
  double hOffset = 20,
  double angle = 0,
  bool isDispose = false,
}) async {
  final PictureRecorder recorder = PictureRecorder();
  final Canvas canvas = Canvas(recorder, rect());
  canvas.drawImage(
      this, Offset.zero, Paint()..filterQuality = FilterQuality.high);
  final Image tImage = _textPaint(
    text,
    style,
    textDirection: textDirection,
    minWidth: minWidth ?? 0,
    maxWidth: maxWidth ?? double.infinity,
    maxLines: maxLines ?? 6,
  );
  _watermakrLayer(
      canvas, tImage, location, opacity, sizeScale, vOffset, hOffset, angle);
  if (isDispose) dispose();
  tImage.dispose();
  final Picture picture = recorder.endRecording();
  return picture.toImageSync(width, height);
}