Skip to content

Instantly share code, notes, and snippets.

@aldiskatel
Created January 24, 2023 06:05
Show Gist options
  • Save aldiskatel/0dd360533bd3fe5336b0e4ae883efb67 to your computer and use it in GitHub Desktop.
Save aldiskatel/0dd360533bd3fe5336b0e4ae883efb67 to your computer and use it in GitHub Desktop.
import 'dart:io';
import 'package:exif/exif.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_watermark/flutter_watermark.dart';
import 'package:http/http.dart' as http;
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
File _image;
String _timestamp;
String _location;
Future takePicture() async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
Map<String, IfdTag> data = await readExifFromBytes(image.readAsBytesSync());
IfdTag dateTime = data[ExifTags.DATE_TIME_ORIGINAL];
_timestamp = dateTime.toString();
IfdTag gpsInfo = data[ExifTags.GPS_INFO];
_location = gpsInfo.toString();
final watermarkedImage = await addWatermark(image);
setState(() {
_image = watermarkedImage;
});
var url = 'your_server_url';
var response = await http.post(
url,
headers: {
"Content-Type": "multipart/form-data",
},
body: {
"image": _image,
},
);
print(response.statusCode);
}
Future<File> addWatermark(File image) async {
return await Watermark.image(
image,
position: WatermarkPosition.bottomRight,
text: _timestamp + '\n' + _location,
textStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.white,
));
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Add Watermark to Image'),
),
body: Center(
child: _image == null
? Text('No image selected.')
: Image.file(_image),
),
floatingActionButton: FloatingAction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment