10

I'm building a Flutter application which needs to add waermark on videos and images. Is there any way to achieve this with firebase (or any other service)? I could do this on client-side but also there i can't find any flutter/Dart package related to video/image processing.

Kindly guide me how to do it.

Thanks

5 Answers 5

6

For videos:

For images:

As for other services, I don't know, but Firebase does not offer this service.

Otherwise, client/app-side, there’s currently not much else for videos, but there's more available for images, you can search https://pub.dev/flutter/packages?q=image+editor. However, for more options, you’ll have to seek out native Android/iOS libraries and custom integrate them through the platform channels.

3
  • Will this work for an Image picker an usecase where I capture an image by opening a camera in the app or choosing an image from gallery Nov 23, 2019 at 14:33
  • Yes, they all should once you've got reference to the File created.
    – TWL
    Nov 25, 2019 at 18:22
  • any luck using FFmpeg ?
    – Nicks
    May 19, 2020 at 21:59
0

For watermark images:

import 'package:extended_image/extended_image.dart';
import 'package:image/image.dart' as ui;
import 'package:path_provider/path_provider.dart';


Future<File> watermarkPicture( File picture, File watermark, String fileName) async {
  ui.Image originalImage = ui.decodeImage(picture.readAsBytesSync());
  ui.Image watermarkImage = ui.decodeImage((watermark.readAsBytesSync()));

  ui.Image image = ui.Image(originalImage.width, originalImage.height);
  ui.drawImage(image, watermarkImage);

  // Easy customisation for the position of the watermark in the next two lines
  final int positionX = (originalImage.width / 2 - watermarkImage.width / 2).toInt();
  final int positionY = (originalImage.height - watermarkImage.height * 1.15).toInt();

  ui.copyInto(
    originalImage,
    image,
    dstX: positionX,
    dstY: positionY,
  );
  final File watermarkedFile = File('${(await getTemporaryDirectory()).path}/$fileName');

  await watermarkedFile.writeAsBytes(ui.encodeJpg(originalImage));

  return watermarkedFile;
}

This is an customisation of this medium article. Because the original solution was not working for me.

1
  • I wonder that it will be necessary applying watermark on each frame with the previous function then probably join all the frames with the following package pub.dev/packages/flutter_ffmpeg
    – Bonobito
    Aug 3, 2021 at 19:49
0

For Image you can use this pacakge https://pub.dev/packages/image_watermark
based on Image pacakge. As parameter you have to pass image bytes and return output image bytes and you can use Image.memory(imgBytes) widget. Add text watermark:

var watermarkedImg = await image_watermark.addTextWatermarkCentered(imgBytes,'watermarkText');

you can customize position ,color of text

var watermarkedImg = await image_watermark.addTextWatermark(
                          imgBytes,             ///image bytes
                          'watermarkText',      ///watermark text
                          20,                   ///position of watermark x coordinate
                          30,                   ///y coordinate
                          color: Colors.green, ///default : Colors.white
                        )

Image watermark:

watermarkedImgBytes = await image_watermark.addImageWatermark(
                              imgBytes, //image bytes
                              imgBytes2,//watermark img bytes
                              imgHeight: 200,   //watermark img height
                              imgWidth: 200,    //watermark img width
                              dstY: 400,
                              dstX: 400);

For video: https://pub.dev/packages/video_manipulation/example

_outputFilepath =
        await VideoManipulation.generateVideo([inputVideopath,watermarkimgPath], outputFilename, framerate, speed);
0

To add image, Try this latest updated package video_watermark

VideoWatermark videoWatermark = VideoWatermark(
    sourceVideoPath: videoPath,
    watermark: Watermark(image: WatermarkSource.file(imagepath)),
    onSave: (path){
        // Get the output file path
    },
);

videoWatermark.generateVideo();
-1

I am not sure about adding watermark over video. But to help people who are looking for watermark over the image can refer to the simple article written by me.

Add Watermark over Image in Flutter

In this article, I have used Image package to apply watermark text or image over Image.There is well explained example program also written about this topic.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.