Reputation: 2839
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
Upvotes: 10
Views: 14929
Reputation: 723
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();
Upvotes: 1
Reputation: 131
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);
Upvotes: 0
Reputation: 11
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.
Upvotes: 0
Reputation: 451
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.
Upvotes: -1
Reputation: 6664
For videos:
https://pub.dev/packages/video_manipulation
Adding still frames to an existing video, e.g. watermarks
.generateVideo(List<String> paths, String filename, int fps, double speed).
Parameters
paths
list of input file paths. Can be images (.jpg or .png) or video files (.mp4) that are used to generate the new video. E.g.:["documents/input.mp4", "documents/watermark.jpg]
For images:
https://pub.dev/packages/image
load, save and manipulate images in a variety of different file formats.
https://github.com/brendan-duncan/image/wiki/Examples
drawString(image, arial_24, 0, 0, 'Hello World');
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.
Upvotes: 6